Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c#: reading html source of a webpage into a string [duplicate]

Tags:

c#

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?

like image 594
Alex Gordon Avatar asked Apr 12 '10 21:04

Alex Gordon


2 Answers

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");
like image 143
Joel Martinez Avatar answered Oct 19 '22 18:10

Joel Martinez


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.

like image 32
dtb Avatar answered Oct 19 '22 18:10

dtb