WebClient.UploadStringCompleted Event

Definition

Occurs when an asynchronous string-upload operation completes.

C#
public event System.Net.UploadStringCompletedEventHandler? UploadStringCompleted;
C#
public event System.Net.UploadStringCompletedEventHandler UploadStringCompleted;

Event Type

Examples

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

C#
public static void UploadStringInBackground2(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);
    string data = "Time = 12:00am temperature = 50";
    client.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadStringCallback2);
    client.UploadStringAsync(uri, data);
}

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

C#
private static void UploadStringCallback2(Object sender, UploadStringCompletedEventArgs e)
{
    string reply = (string)e.Result;
    Console.WriteLine(reply);
}

Remarks

Oprez

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 string upload operation completes. Asynchronous string uploads are started by calling the UploadStringAsync methods.

The UploadStringCompletedEventHandler is the delegate for this event. The UploadStringCompletedEventArgs class provides the event handler with event data.

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

Applies to

Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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