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.

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

void OpenResourceForPosting( String^ address )
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   // Specify that the OpenWriteCallback method gets called
   // when the writeable stream is available.
   client->OpenWriteCompleted += gcnew 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.

void OpenWriteCallback2( Object^ /*sender*/, OpenWriteCompletedEventArgs^ e )
   Stream^ body = nullptr;
   StreamWriter^ s = nullptr;
      body = dynamic_cast<Stream^>(e->Result);
      s = gcnew StreamWriter( body );
      s->AutoFlush = true;
      s->Write( "This is content data to be sent to the server." );
      if ( s != nullptr )
      if ( body != nullptr )


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