OpenWriteCompletedEventHandler Delegate
Collapse the table of content
Expand the table of content

OpenWriteCompletedEventHandler Delegate


Represents the method that will handle the OpenWriteCompleted event of a WebClient.

Namespace:   System.Net
Assembly:  System (in System.dll)

public delegate void OpenWriteCompletedEventHandler(
	object sender,
	OpenWriteCompletedEventArgs e


Type: System.Object

The source of the event.

Type: System.Net.OpenWriteCompletedEventArgs

A OpenWriteCompletedEventArgs containing event data.

When you create a OpenWriteCompletedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate.

Legacy Code Example

The following code example demonstrates opening a stream to write data to be uploaded.

public static void OpenResourceForPosting (string address)
    WebClient client = new WebClient ();
    Uri uri = new Uri(address);

    // Specify that the OpenWriteCallback method gets called
    // when the writeable stream is available.
    client.OpenWriteCompleted += new OpenWriteCompletedEventHandler (OpenWriteCallback2);
    client.OpenWriteAsync (uri);
    // Applications can perform other tasks
    // while waiting for the upload to complete.

The following method is called when the stream is available.

private static void OpenWriteCallback2 (Object sender, OpenWriteCompletedEventArgs e)
    Stream body = null;
    StreamWriter s = null;

        body = (Stream)e.Result;
        s = new StreamWriter (body);
        s.AutoFlush = true;
        s.Write ("This is content data to be sent to the server.");
        if (s != null)
            s.Close ();

        if (body != null)
            body.Close ();

.NET Framework
Available since 2.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft