c# - Downloading string from URL and loading ListBox with the returned data? -


i'm downloading string file website, need information , load listbox text, unfortunately im getting error every time click in button event.

my code:

var httpclient = new httpclient();             var text = await httpclient.getstringasync(@"http://photo-51.netau.net/changelog");             streamreader sr = new streamreader(@text, system.text.encoding.default);//here have invalid path character error             string line;              while ((line = sr.readline()) != null)             {                 listbox1.items.add(line);             } 

i have , invalid character in path. how can fix it?

streamreader you're using expects path file read. @text you're passing treated path file, that's why exception.

you can reference msdn, streamreader constructor. can see, string parameter defined

the complete file path read.

now there multiple ways of reading string line line, i'll put here 1 requires least changes in original code

var httpclient = new httpclient(); var text = await httpclient.getstringasync(@"http://photo-51.netau.net/changelog"); stringreader sr = new stringreader(text);  string line; while((line = sr.readline()) != null) {   listbox1.items.add(line); } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -