示例
[Visual Basic, C#, C++] 下面的示例将文件从 http://www.contoso.com 下载到本地硬盘。[Visual Basic] 
Dim remoteUri As String = "http://www.contoso.com/library/homepage/images/"
Dim fileName As String = "ms-banner.gif"
Dim myStringWebResource As String = Nothing
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Concatenate the domain with the Web resource filename. Because DownloadFile 
'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
myStringWebResource = remoteUri + fileName
Console.WriteLine("Downloading File ""{0}"" from ""{1}"" ......." + ControlChars.Cr + ControlChars.Cr, fileName, myStringWebResource)
' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
myWebClient.DownloadFile(myStringWebResource, fileName)
Console.WriteLine("Successfully Downloaded file ""{0}"" from ""{1}""", fileName, myStringWebResource)
Console.WriteLine((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + Application.StartupPath))[C#] 
string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource,fileName);        
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);[C++] 
String* remoteUri = S"http://www.contoso.com/library/homepage/images/";
String* fileName = S"ms-banner.gif", * myStringWebResource = 0;
// Create a new WebClient instance.
WebClient* myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = String::Concat(remoteUri, fileName);
Console::WriteLine(S"Downloading File \" {0}\" from \" {1}\" .......\n\n", fileName, myStringWebResource);
   // Download the Web resource and save it into the current filesystem folder.
   myWebClient->DownloadFile(myStringWebResource, fileName);
Console::WriteLine(S"Successfully Downloaded File \" {0}\" from \" {1}\"", fileName, myStringWebResource);
   Console::WriteLine(S"\nDownloaded file saved in the following file system folder:\n\t {0}", Application::StartupPath);[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的“语言筛选器”按钮 。