Sixem

.NET Download File With Progress

Aug 3rd, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.89 KB | None | 0 0
  1. Imports System.Net
  2. Public Class Download
  3.     Public Shared Function Download_File(ByVal URL_ As String, ByVal Path_ As String)
  4.         Dim Download_Handle As New Net.WebClient
  5.         AddHandler Download_Handle.DownloadProgressChanged, AddressOf DownloadProgressCallback
  6.         Download_Handle.DownloadFileAsync(New Uri(URL_), Path_)
  7.         Return 0
  8.     End Function
  9.     Public Shared Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
  10.         Dim File_Size As Long = e.TotalBytesToReceive
  11.         Dim File_Received As Long = e.BytesReceived
  12.         Dim Progress As String = String.Format("{0} kB / {1} kB - {2}%", Math.Round((File_Received / 1024)), Math.Round((File_Size / 1024)), e.ProgressPercentage)
  13.         If e.ProgressPercentage = 100 Then
  14.             MessageBox.Show("Download complete!", "100%")
  15.         End If
  16.     End Sub
  17. End Class
Add Comment
Please, Sign In to add comment