Create a file downloader with progress
Even if you already know, just sharing.
●First of all we need to import the 'Net' namespace.
●Then we need to create an instance of the 'WebClient' class found in the namespace. The class contains some useful functions to send or receive data related to a URL.
●The 'WithEvents' specifier determines weather or not the declared member can control events. Create the following event to check the progress of the file being downloaded by the web client. Lets take for example you have a progress bar.
●Now to download the file in contrast to the event. Lets say you're using a button.
Took me a while to figure it out, at first I was just using 'DownloadFile' which didn't raise the event so it didn't work.
●First of all we need to import the 'Net' namespace.
Code:
Imports System.Net
Code:
Private WithEvents WebClient1 As New WebClient
Code:
Private Sub WebClient1_DownloadProgressChanged(ByVal sender As System.Object, ByVal e As Net.DownloadProgressChangedEventArgs) Handles WebClient1.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebClient1.DownloadFileAsync("http://www.mpgh.net/forum/images/debatefort.png", "debatefort logo.png")
End Sub
