Reputation: 13
I have a directory that Contains x amount of text files. The first Line on each text file needs to be added to a list box in a WPF application when the application starts. How can I read the first line from every text file and add each line to my list box?
Upvotes: 1
Views: 333
Reputation: 6398
Something like this should do:
foreach (var filePath in Directory.EnumerateFiles(@"c:\folder"))
{
using (var reader = new StreamReader(filePath))
{
var line = reader.ReadLine();
listBox.Items.Add(line);
}
}
Upvotes: 1