C# WebClient OpenWrite(String)

Description

WebClient OpenWrite(String) Opens a stream for writing data to the specified resource.

Syntax

WebClient.OpenWrite(String) has the following syntax.


public Stream OpenWrite(
  string address
)

Parameters

WebClient.OpenWrite(String) has the following parameters.

  • address - The URI of the resource to receive the data.

Returns

WebClient.OpenWrite(String) method returns A Stream used to write data to the resource.

Example

The following code example reads data from the command line and uses OpenWrite to obtain a stream for writing the data.


using System;//from   w  ww  .ja v a2s  . co m
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;

public class Example
{
    public static void Main()
    {

        string uriString = "http://yourServer";
        string postData = "yourData";
        byte[] postArray = Encoding.ASCII.GetBytes(postData);
        WebClient myWebClient = new WebClient();
        Console.WriteLine("Uploading to {0} ...", uriString);
        Stream postStream = myWebClient.OpenWrite(uriString);

        postStream.Write(postArray, 0, postArray.Length);
        postStream.Close();

    }
}




















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient