WebClient.UploadFileCompleted Event
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when an asynchronous file-upload operation completes.
public:
event System::Net::UploadFileCompletedEventHandler ^ UploadFileCompleted;
public 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
The following code example shows an implementation of a handler for this event.
void UploadFileCallback2( Object^ /*sender*/, UploadFileCompletedEventArgs^ e )
{
String^ reply = System::Text::Encoding::UTF8->GetString( e->Result );
Console::WriteLine( reply );
}
private static void UploadFileCallback2(Object sender, UploadFileCompletedEventArgs e)
{
string reply = System.Text.Encoding.UTF8.GetString(e.Result);
Console.WriteLine(reply);
}
Private Shared Sub UploadFileCallback2(ByVal sender As Object, ByVal e As System.Net.UploadFileCompletedEventArgs)
Dim reply As String = System.Text.Encoding.UTF8.GetString(e.Result)
Console.WriteLine(reply)
End Sub
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.
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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: