WebClient.UploadFileCompleted Event

Definition

Occurs when an asynchronous file-upload operation completes.

public event System.Net.UploadFileCompletedEventHandler? UploadFileCompleted;
public event System.Net.UploadFileCompletedEventHandler UploadFileCompleted;

Event Type

Examples

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

// 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.");
}

The following code example shows an implementation of a handler for this event.

private static void UploadFileCallback2(Object sender, UploadFileCompletedEventArgs e)
{
    string reply = System.Text.Encoding.UTF8.GetString(e.Result);
    Console.WriteLine(reply);
}

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This event is raised each time an asynchronous file upload operation completes. Asynchronous file uploads are started by calling the UploadFileAsync methods.

The UploadFileCompletedEventHandler is the delegate for this event. 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

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1