C# WebClient UploadFile(String, String)
Description
WebClient UploadFile(String, String)
Uploads the specified
local file to a resource with the specified URI.
Syntax
WebClient.UploadFile(String, String)
has the following syntax.
public byte[] UploadFile(
string address,
string fileName
)
Parameters
WebClient.UploadFile(String, String)
has the following parameters.
address
- The URI of the resource to receive the file. For example, ftp://localhost/samplefile.txt.fileName
- The file to send to the resource. For example, "samplefile.txt".
Returns
WebClient.UploadFile(String, String)
method returns
Example
The following code example uploads the specified file to the specified URI using UploadFile.
/*from w w w . j av a2 s .com*/
using System;
using System.Net;
using System.Net.Sockets;
public class Example
{
public static void Main()
{
String uriString = "http://your Server";
WebClient myWebClient = new WebClient();
string fileName = "index.htm";
byte[] responseArray = myWebClient.UploadFile(uriString,fileName);
Console.WriteLine("\nResponse Received.The contents of the file uploaded are:\n{0}",
System.Text.Encoding.ASCII.GetString(responseArray));
}
}