Reputation: 11673
string[] files = Directory.GetFiles("C:/Users/ME/Desktop/items/", ".txt", SearchOption.AllDirectories);
How would I display the returned results in a textbox that I have created?
Upvotes: 1
Views: 109
Reputation:
Provided this is a multi-line textbox:
foreach (string file in files)
{
YourTextBox.Text += file + '\r\n';
}
Upvotes: 0
Reputation: 393064
textbox1.Text = string.Join(Environment.NewLine, files);
This internally uses a StringBuilder or equivalent for optimum performance and heap fragmentation prevention
Upvotes: 3
Reputation: 44931
System.Text.StringBuilder sbText = new System.Text.StringBuilder(10000);
foreach (string sFile in files) {
sbText.AppendLine(sFile);
}
TextBox1.Text = sbText.ToString();
Upvotes: 0
Reputation: 33738
foreach (string file in files) {
textbox1.Text += file + Environment.NewLine;
}
Upvotes: 1