c# - Download TextFile from internet and load a ListBox with the content -
i'm downloading txt file internet unfortunately, can't load listbox content file.
that's code:
var webrequest = webrequest.create(@"http://photo-51.netau.net/changelog"); using (var response = webrequest.getresponse()) using (var content = response.getresponsestream()) using (var reader = new streamreader(content)) { list<string> lines = new list<string>(); var strcontent = reader.readtoend(); string line; while((line = reader.readline()) != null){ lines.add(line); listbox1.items.add(lines); } } when run it, nothing happens.
you first read full stream content strcontent, thus, when reader.readline() there's nothing left read.
if remove "var strcontent = reader.readtoend();" work.
also simple way reduce code , make work this:
list<string> lines = new list<string>(); reader.addrange(sr.readtoend().split("\r\n".tochararray()));
Comments
Post a Comment