Download the resource with the specified URI to a local file in CSharp
Description
The following code shows how to download the resource with the specified URI to a local file.
Example
using System;//from w ww . j a va2 s . co m
using System.Net;
using System.Net.Sockets;
public class Example
{
public static void Main()
{
string remoteUri = "http://www.java2s.com/";
string fileName = "index.htm", myStringWebResource = null;
WebClient myWebClient = new WebClient();
myStringWebResource = remoteUri + fileName;
Console.WriteLine(myStringWebResource);
myWebClient.DownloadFile(new Uri(myStringWebResource), fileName);
Console.WriteLine(fileName, myStringWebResource);
}
}
The code above generates the following result.