Download with Progressbar

Download something from internet and show progress using progressbar

Public Class Form1

    Private Sub downloadFile(ByVal sourcePath As string, ByVal destinationPath As string)
        Dim wc As New System.Net.WebClient()
        AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgressCallback

        wc.DownloadFileAsync(New System.Uri(sourcePath), destinationPath)

        ' Uncomment this if you want to pause in this sub while the file downloads
        'While wc.IsBusy = True
        '    Application.DoEvents()
        'End While

    End Sub

    Private Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
        ProgressBar1.Maximum = e.TotalBytesToReceive
        ProgressBar1.Value = e.BytesReceived
    End Sub

End Class

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s