C# WebClient DownloadFile(Uri, String)
Description
WebClient DownloadFile(Uri, String)
Downloads the
resource with the specified URI to a local file.
Syntax
WebClient.DownloadFile(Uri, String)
has the following syntax.
public void DownloadFile(
Uri address,
string fileName
)
Parameters
WebClient.DownloadFile(Uri, String)
has the following parameters.
address
- The URI specified as a String, from which to download data.fileName
- The name of the local file that is to receive the data.
Returns
WebClient.DownloadFile(Uri, String)
method returns
Example
Downloads the resource with the specified URI to a local file.
using System;/*from w ww . ja v a 2 s . c om*/
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);
}
}