I want to select a simple .txt file that contains lines of strings using a FileUpload control. But instead of actually saving the file I want to loop through each line of text and display each line in a ListBox control.
Example of a text file:
test.txt
123jhg345
182bdh774
473ypo433
129iiu454
What is the best way to accomplish this?
What I have so far:
private void populateListBox()
{
FileUpload fu = FileUpload1;
if (fu.HasFile)
{
//Loop trough txt file and add lines to ListBox1
}
}
open the file into a StreamReader and use
If you want to know how to get the file/date into a stream please say in what form you get the file(s bytes)
There are a few different ways of doing this, the ones above are good examples.
Here's a working example:
There is this as well, using HttpPostedFileBase in MVC: