If you want to write some code to download data a location specified by a URI, simply you can use the WebClient DownloadData and DownloadFile methods; this data can be either an array of bytes or a file. WebClient simplifies downloading of files and bytes in files, as these are common tasks when dealing with the Web. The more traditional stream-based method for downloading can also be accessed via the OpenRead method on the WebClient.

Check the snippet code below:

string uri = "http://localhost/mysite/upload.aspx";

// make a client
WebClient client = new WebClient();

// get the contents of the file
Console.WriteLine("Downloading {0} " + uri);
// download the page and store the bytes
byte[] bytes = client.DownloadData(uri);
// Write the HTML out
string page = Encoding.ASCII.GetString(bytes);
Console.WriteLine(page);

You could also have downloaded the file itself:

// go get the file
Console.WriteLine("Retrieving file from {1}...rn", uri);
// get file and put it in a temp file
string tempFile = Path.GetTempFileName();
client.DownloadFile(uri, tempFile);
Console.WriteLine("Downloaded {0} to {1}",uri,tempFile);

Popularity: 2% [?]