WebClient.DownloadFileCompleted WebClient.DownloadFileCompleted WebClient.DownloadFileCompleted WebClient.DownloadFileCompleted Event

Definition

Occurs when an asynchronous file download operation completes.

public:
 event System::ComponentModel::AsyncCompletedEventHandler ^ DownloadFileCompleted;
public event System.ComponentModel.AsyncCompletedEventHandler DownloadFileCompleted;
member this.DownloadFileCompleted : System.ComponentModel.AsyncCompletedEventHandler 
Public Custom Event DownloadFileCompleted As AsyncCompletedEventHandler 

Examples

The following code example demonstrates setting an event handler for this event.

// Sample call : DownLoadFileInBackground2 ("http://www.contoso.com/logs/January.txt");
void DownLoadFileInBackground2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);
   
   // Specify that the DownloadFileCallback method gets called
   // when the download completes.
   client->DownloadFileCompleted += gcnew AsyncCompletedEventHandler( DownloadFileCallback2 );
   
   // Specify a progress notification handler.
   client->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler( DownloadProgressCallback );
   client->DownloadFileAsync( uri, "serverdata.txt" );
}


// Sample call : DownLoadFileInBackground2 ("http://www.contoso.com/logs/January.txt");
public static void DownLoadFileInBackground2 (string address)
{
    WebClient client = new WebClient ();
    Uri uri = new Uri(address);

    // Specify that the DownloadFileCallback method gets called
    // when the download completes.
    client.DownloadFileCompleted += new AsyncCompletedEventHandler (DownloadFileCallback2);
    // Specify a progress notification handler.
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
    client.DownloadFileAsync (uri, "serverdata.txt");
}

'  Sample call : DownLoadFileInBackground2 ("http:' www.contoso.com/logs/January.txt")
Public Shared Sub DownLoadFileInBackground2(ByVal address As String)

	Dim client As WebClient = New WebClient()

	'  Specify that the DownloadFileCallback method gets called
	'  when the download completes.
	AddHandler client.DownloadFileCompleted, AddressOf DownloadFileCallback2
	'  Specify a progress notification handler.
	AddHandler client.DownloadProgressChanged, AddressOf DownloadProgressCallback
                      Dim uri as Uri = New Uri(address)
	client.DownloadFileAsync(uri, "serverdata.txt")
End Sub

Remarks

This event is raised each time an asynchronous file download operation completes. Asynchronous file downloads are started by calling the DownloadFileAsync methods.

The AsyncCompletedEventHandler is the delegate for this event. The AsyncCompletedEventArgs class provides the event handler with event data.

For more information about how to handle events, see Handling and Raising Events.

Applies to