Hi Guys
am trying to view for each loop values in a multi line textbox but am still failing, below is my code
any help?
}
DirectoryInfo dir = new DirectoryInfo(startFolder);
IEnumerable
string searchTerm = "the";
var queryMatchingFiles =
from file in fileList
where file.Extension == ".pdf"
let fileText = GetFileText(file.FullName)
where fileText.Contains(searchTerm)
select file.FullName;
//Console.WriteLine("The term \"{0}\" was found in:", searchTerm);
textBox2.Text = "The term \"{0}\" was found in:";
foreach (string filename in queryMatchingFiles)
{
//Console.WriteLine(filename);
textBox2.Text += filename.ToString();
}
}


Tahir AnsariRank #366 · 6.8K reputationPosted Sep 16, 2023, 4:42 AM EDT
string startFolder = @"C:\YourFolderPath"; // Replace with your folder path DirectoryInfo dir = new DirectoryInfo(startFolder); IEnumerable fileList = dir.GetFiles("*.*", SearchOption.AllDirectories); string searchTerm = "the"; var queryMatchingFiles = from file in fileList where file.Extension == ".pdf" let fileText = GetFileText(file.FullName) where fileText.Contains(searchTerm) select file.FullName; textBox2.Clear(); // Clear the existing content in the textbox textBox2.AppendText($"The term \"{searchTerm}\" was found in:{Environment.NewLine}"); foreach (string filename in queryMatchingFiles) { textBox2.AppendText(filename + Environment.NewLine); }Marvin kakuruRank #3,979 · 374 reputationPosted Sep 16, 2023, 4:53 AM EDT
Tahir thanks a lot, AppendText has worked perfectly.
thanks again
Saravanan GanesanRank #153 · 15.1K reputationPosted Sep 24, 2023, 1:15 PM EDT
To display the filenames found in the multi-line TextBox, you should use the
AppendTextmethod instead of setting theTextproperty directly. Modify your loop as follows:foreach (string filename in queryMatchingFiles)
{
textBox2.AppendText(filename + Environment.NewLine);
}
This appends each filename to the existing text in the TextBox with proper line breaks.