C# WebClient UploadFile(Uri, String)
Description
WebClient UploadFile(Uri, String)
Uploads the specified
local file to a resource with the specified URI.
Syntax
WebClient.UploadFile(Uri, String)
has the following syntax.
public byte[] UploadFile(
Uri address,
string fileName
)
Parameters
WebClient.UploadFile(Uri, 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(Uri, String)
method returns
Example
/*from w ww . j av a2 s . co m*/
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(new Uri(uriString),fileName);
Console.WriteLine("\nResponse Received.The contents of the file uploaded are:\n{0}",
System.Text.Encoding.ASCII.GetString(responseArray));
}
}