How to list text files in the selected directory in a listbox?
To get the txt files, try this:
var folder = @"C:\Users\Ece\Documents\Testings";
var txtFiles = Directory.GetFiles(folder, "*.txt");
listBox.Items.AddRange(txtFiles);
// What directory are the files in?...
DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestDirectory");
// What type of file do we want?...
FileInfo[] Files = dinfo.GetFiles("*.txt");
// Iterate through each file, displaying only the name inside the listbox...
foreach( FileInfo file in Files )
{
listbox1.Items.Add(file.Name);
}
// A statement, followed by a smiley face... That oughta do it. ;o)