C# WebClient UploadFile(Uri, String, String)

Description

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

Syntax

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


public byte[] UploadFile(
  Uri address,//www . ja va2  s  . co  m
  string method,
  string fileName
)

Parameters

WebClient.UploadFile(Uri, 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(Uri, String, String) method returns

Example


using System;/*  www.  j av a2  s  .  c  om*/
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),"POST",fileName);
            System.Text.Encoding.ASCII.GetString(responseArray);
    
   }
}




















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient