WebClient.UploadProgressChanged Event

 

Occurs when an asynchronous upload operation successfully transfers some or all of the data.

Namespace:   System.Net
Assembly:  System (in System.dll)

Public Event UploadProgressChanged As UploadProgressChangedEventHandler

This event is raised each time an asynchronous upload makes progress. This event is raised when uploads are started using any of the following methods.

Method

Description

UploadDataAsync

Sends a Byte array to the resource, without blocking the calling thread.

UploadFileAsync

Sends a local file to the resource, without blocking the calling thread.

UploadValuesAsync

Sends a NameValueCollection to the resource and returns a Byte array containing any response, without blocking the calling thread.

The UploadProgressChangedEventHandler is the delegate for this event. The UploadProgressChangedEventArgs class provides the event handler with event data.

For more information about handling events, see NIB: Consuming Events.

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

'  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.

Private Shared Sub UploadProgressCallback(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)

    '  Displays the operation identifier, and the transfer progress.
    Console.WriteLine("{0}    uploaded {1} of {2} bytes. {3} % complete...", _
     CStr(e.UserState), e.BytesSent, e.TotalBytesToSend, e.ProgressPercentage)
End Sub
Private Shared Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)

    '  Displays the operation identifier, and the transfer progress.
    Console.WriteLine("0}    downloaded 1} of 2} bytes. 3} % complete...", _
     CStr(e.UserState), e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage)
End Sub

.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: