WebClient.UploadFileCompleted Event


在异步文件上载操作完成时发生。Occurs when an asynchronous file-upload operation completes.

 event System::Net::UploadFileCompletedEventHandler ^ UploadFileCompleted;
public event System.Net.UploadFileCompletedEventHandler UploadFileCompleted;
member this.UploadFileCompleted : System.Net.UploadFileCompletedEventHandler 
Public Custom Event UploadFileCompleted As UploadFileCompletedEventHandler 
Public Event UploadFileCompleted As UploadFileCompletedEventHandler 


下面的代码示例演示如何为此事件设置事件处理程序。The following code example demonstrates setting an event handler for this event.

// Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
void UploadFileInBackground2( String^ address, String^ fileName )
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   client->UploadFileCompleted += 
     gcnew UploadFileCompletedEventHandler (UploadFileCallback2);
   // Specify a progress notification handler.
   client->UploadProgressChanged += 
       gcnew UploadProgressChangedEventHandler( UploadProgressCallback );
   client->UploadFileAsync( uri, "POST", fileName );
   Console::WriteLine( "File upload started." );

// Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
public static void UploadFileInBackground2 (string address, string fileName)
    WebClient client = new WebClient ();
    Uri uri = new Uri(address);

    client.UploadFileCompleted += new UploadFileCompletedEventHandler (UploadFileCallback2);

 // Specify a progress notification handler.
 client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback);
    client.UploadFileAsync (uri, "POST", fileName);
    Console.WriteLine ("File upload started.");

'  Sample call: UploadFileInBackground2("http:' www.contoso.com/fileUpload.aspx", "data.txt")
Public Shared Sub UploadFileInBackground2(ByVal address As String, ByVal fileName As String)

    Dim client As WebClient = New WebClient()
                Dim uri as Uri =  New Uri(address)
    AddHandler client.UploadFileCompleted, AddressOf UploadFileCallback2

    '  Specify a progress notification handler.
    AddHandler client.UploadProgressChanged, AddressOf UploadProgressCallback
    client.UploadFileAsync(uri, "POST", fileName)
    Console.WriteLine("File upload started.")
End Sub


每次异步文件上传操作完成时都会引发此事件。This event is raised each time an asynchronous file upload operation completes. 异步文件上传通过调用 UploadFileAsync 方法来启动。Asynchronous file uploads are started by calling the UploadFileAsync methods.

UploadFileCompletedEventHandler 是此事件的委托。The UploadFileCompletedEventHandler is the delegate for this event. UploadFileCompletedEventArgs 类向事件处理程序提供事件数据。The UploadFileCompletedEventArgs class provides the event handler with event data.

有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.

Applies to