private void button6_Click(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
}
And I have a RichTextBox
:
private void richTextBox4_TextChanged(object sender, EventArgs e)
{
}
How can I return / output the data 开发者_JAVA百科from the method into the RichTextBox
?
Once you get the filenames, you can use Enumerable.Aggregate to turn them into a string and set that string as the text for the Rich Text Box:
private void button6_Click(object sender, EventArgs e)
{
richTextBox4.Text =
Directory.GetFiles(@"C:\MyDir\")
.Aggregate("", (text, pathName) =>
text += String.Format("{0}\n", pathName))
);
}
foreach(string path in filePaths) {
richTextBox4.AppendText(path + Environment.NewLine);
}
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
richTextBox4.Text = string.Join(Environment.NewLine, filePaths);
精彩评论