C# WebClient UploadFile(String, String, String)

Description

WebClient UploadFile(String, String, String) Uploads the specified local file to the specified resource, using the specified method.

Syntax

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


public byte[] UploadFile(
  string address,//ww  w . j a va  2s  .c o  m
  string method,
  string fileName
)

Parameters

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

  • address - The URI of the resource to receive the file.
  • method - The method used to send the file to the resource. If null, the default is POST for http and STOR for ftp.
  • fileName - The file to send to the resource.

Returns

WebClient.UploadFile(String, String, String) method returns

Example


using System;/*  w w  w.  j  av a2s . c o m*/
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,"POST",fileName);
            Console.WriteLine("\nResponse Received.The contents of the file uploaded are:\n{0}",
            System.Text.Encoding.ASCII.GetString(responseArray));
    
   }
}




















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient