C# WebClient DownloadFile(String, String)

Description

WebClient DownloadFile(String, String) Downloads the resource with the specified URI to a local file.

Syntax

WebClient.DownloadFile(String, String) has the following syntax.


public void DownloadFile(
  string address,
  string fileName
)

Parameters

WebClient.DownloadFile(String, String) has the following parameters.

  • address - The URI from which to download data.
  • fileName - The name of the local file that is to receive the data.

Returns

WebClient.DownloadFile(String, String) method returns

Example

The following code example downloads a file from http://www.java2s.com to the local hard drive.


using System;//from   w w w . j a  v a 2  s . c o  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(myStringWebResource, fileName);
        Console.WriteLine(fileName, myStringWebResource);

    }
}




















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient