How would I make the Progress Bars Value = The Percentage of a file being downloaded using a Webclient?
Printable View
How would I make the Progress Bars Value = The Percentage of a file being downloaded using a Webclient?
It would look something like this:
Code:Dim WithEvents wc As New WebClient
Private Sub wc_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles wc.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
wc.DownloadFile("http://server/somefile.dat", "C:\Temp\download.dat")
End Sub
The WebClient.DownloadProgressChanged event is raised for asynchronous methods only, e.g. DownloadFileAsync.
The easiest way to do this is to use My.Computer.Network.DownloadFile. It will display its own modeless dialogue with a Cancel button. If you prefer to display progress in your own form then WebClient.DownloadFileAsync would be the way to go.