Read HTML into string from URL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I would like to read the html into a string from a certain URL. How is this
done?

Best regards Jesper.
 
Jesper,

Take a look at the documentation of the WebClient class, it contains this
code in the DownloadData(string) method

Console.Write("\nPlease enter a URI (for example, http://www.contoso.com):
");
string remoteUri = Console.ReadLine();

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Download home page data.
Console.WriteLine("Downloading " + remoteUri);
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = myWebClient.DownloadData (remoteUri);

// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDataBuffer);
Console.WriteLine(download);

Console.WriteLine("Download successful.");


You need to add a using statement for System.Net for this.


- Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top