Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading text file into listbox

What I am wanting to achieve is loading a text file into a listbox. It seems simple enough but I need to recognise in the text file when there is a new line, and each new line needs to be a new item in the listbox.

If this is possible, a reply would be much appreciated.

like image 278
Shannon Rothe Avatar asked Dec 04 '22 04:12

Shannon Rothe


1 Answers

This will work

List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(f))
{
    string line;
    while ((line = r.ReadLine()) != null)
    {
        lines.Add(line);
    }
}
like image 50
gaurawerma Avatar answered Dec 21 '22 00:12

gaurawerma