Reputation: 111
I am writing an app in c#, Is there a way to download a HTML page by giving my program its URL only. Foe example my program will get the URL www.google.com and download the HTML page?
Upvotes: 6
Views: 17147
Reputation: 16032
Use the WebClient class.
This is extracted from a sample on the msdn doc page:
using System;
using System.Net;
using System.IO;
public static string Download (string uri)
{
WebClient client = new WebClient ();
Stream data = client.OpenRead (uri);
StreamReader reader = new StreamReader (data);
string s = reader.ReadToEnd ();
data.Close ();
reader.Close ();
return s;
}
Upvotes: 8