PostCreate a file downloader with progress

Posts 1–7 of 7 · Page 1 of 1
Create a file downloader with progress
Even if you already know, just sharing.

●First of all we need to import the 'Net' namespace.

Code:
Imports System.Net
●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.

Code:
Private WithEvents WebClient1 As New WebClient
●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.

Code:
Private Sub WebClient1_DownloadProgressChanged(ByVal sender As System.Object, ByVal e As Net.DownloadProgressChangedEventArgs) Handles WebClient1.DownloadProgressChanged
    ProgressBar1.Value = e.ProgressPercentage
End Sub
●Now to download the file in contrast to the event. Lets say you're using a button.

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
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.
Quote Originally Posted by Raow View Post
@Geometrical
It's really good what you're doing dude, this section has been kind of dead for a bit now with only the occaisonal noob trying to leach.
But, just make sure to check if a tutorial exists before you make one.
http://www.mpgh.net/forum/161-progra...tutorials.html

Good job man, and keep it up.
Well, dead section is dead and I have nothing better to do.
Quote Originally Posted by Geometrical View Post
Well, dead section is dead and I have nothing better to do.
Fair enough dude, if you find tutorials have already been posted try to add your own thing.

For this tut, maybe like Pause/Resume, download rate, etc.
Good, Good job!! i like it
Nice and neat tut.
Keep up the good work!
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us