[Visual Basic, C#] 下面的示例使用 UploadFile 将指定文件上载到指定 URI。由服务器返回的任何响应都显示到控制台。[Visual Basic, C#] 注意   此示例显示如何使用 UploadFile 的一个重载版本。有关其他可用示例,请参阅单独的重载主题。
[Visual Basic] 
Console.Write(ControlChars.Cr + "Please enter the URL to post data to : ")
Dim uriString As String = Console.ReadLine()' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the fully qualified path of the file to be uploaded to the URL")Dim fileName As String = Console.ReadLine()
Console.WriteLine("Uploading {0} to {1} ...", fileName, uriString)' Upload the file to the Url using the HTTP 1.0 POST.
Dim responseArray As Byte() = myWebClient.UploadFile(uriString, "POST", fileName)' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response Received.The contents of the file uploaded are: " + ControlChars.Cr + "{0}", Encoding.ASCII.GetString(responseArray))
[C#] 
         Console.Write("\nPlease enter the URL to post data to : ");
         String uriString = Console.ReadLine();         // Create a new WebClient instance.
         WebClient myWebClient = new WebClient();         Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URL");
         string fileName = Console.ReadLine();         Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);                  
         // Upload the file to the URL using the HTTP 1.0 POST.
         byte[] responseArray = myWebClient.UploadFile(uriString,"POST",fileName);         // Decode and display the response.
         Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));