Question

I would like to use ListBox1.loadfromfile method in .NET, but it doesn't seem to exists or have anything equivalent to that method. I have searched on MSDN library site and I came empty handed. Is there a equivalent method in .NET?

Thanks in advance,

Was it helpful?

Solution

This can get you close:

listBox1.Items.AddRange(File.ReadAllLines(@"c:\test.txt"));

OTHER TIPS

I don't know of anything in .NET that mimics that particular Delphi construct. You'll probably have to load the lines of text manually into a list box. It's pretty simple:

// Read the file line by line
System.IO.StreamReader file = new System.IO.StreamReader(@"c:\somefile.txt");
while((line = file.ReadLine()) != null)
{
    //Add the line to the list box
    listBox1.Items.Add(line);
}

file.Close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top