Reputation: 11
I've been looking for awhile but everything I find doesn't work. I'm trying to take the text from my .txt file and have it placed in my listbox when the form loads.
I tried const string sPath = "TextFile1.txt"; listBox1.Text = File.ReadAllText(sPath);
but it won't work the listbox is blank when I open the form. I want it to be able to get the current directory of the .txt so it will work on any computer. Thanks.
Upvotes: 1
Views: 65
Reputation: 530
var content = File.ReadAllLines("TextFile1.txt");
this.listBox1.Items.AddRange(content);
Upvotes: 0
Reputation: 113
Use streamreader , read each line into an array and set the array to the Listbox. Listbox.items.add (Array[x]) I'm assuming there are no separators in the text ?
Upvotes: 1