I would like to be able to read the html source of a certain webpage into a string in c# using winforms
how do I do this?
string html = new WebClient().DownloadString("http://twitter.com");
And now with async/await hotness in C# 5
string html = await new WebClient().DownloadStringTaskAsync("http://github.com");
Have a look at WebClient.DownloadString:
using (WebClient wc = new WebClient())
{
string html = wc.DownloadString(address);
}
You can use WebClient.DownloadStringAsync or a BackgroundWorker to download the file without blocking the UI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With