Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using the WebClient Class To Track Download Progress
#1
Using this code snippet, you should be able to download any file to your computer and track it's progress using a progressbar or a label (Or any other control which you desire). Below is a sample snippet, so be sure to change variable names to match your project!

[code2=vbnet]Imports System.Net
Public Class Form1

Private Sub btn_downloadStart_Click(sender As System.Object, e As System.EventArgs) Handles btn_downloadStart.Click
Dim wc As New WebClient 'This allows us to actually download the files
AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgressChanged 'Link the progresschanged event with our subroutine
AddHandler wc.DownloadFileCompleted, AddressOf DownloadFileCompleted 'Link the downloadfilecompleted event with our subrouting
wc.DownloadFileAsync(New System.Uri("File URL"), "Local Path") 'Actually download the file (on another thread), change File URL and Local Path to your information
End Sub

Public Sub DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
progress_download.Value = e.ProgressPercentage 'Displays download progress on a progress bar
lbl_details.Text = e.BytesReceived & "/" & e.TotalBytesToReceive 'Displays download progress (as fraction) in a label
End Sub

Public Sub DownloadFileCompleted(sender As Object, e As EventArgs)
MsgBox("The file has completed downloading!") 'Tell the user the download is complete
End Sub
End Class[/code2]

A video tutorial for this code snippet should be coming soon!
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Keeping Track of Multiple Things (Alternative to an Array) brandonio21 0 6,614 11-27-2011, 03:02 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)