Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private getSize = Me.FileSize(TextBox1.Text)
- Private Function GetFileSize(ByVal MyFilePath As String)
- Dim fileDetail As IO.FileInfo
- fileDetail = My.Computer.FileSystem.GetFileInfo(MyFilePath)
- Return fileDetail.Length
- End Function
- Sub DoDownload()
- DownloadFile(TextBox1.Text, TextBox2.Text)
- End Sub
- Sub DownloadFile(ByVal uri As String, ByVal destFile As String, _
- Optional ByVal username As String = Nothing, Optional ByVal pwd As String = _
- Nothing)
- Dim wc As New System.Net.WebClient
- If Not username Is Nothing AndAlso Not pwd Is Nothing Then
- wc.Credentials = New System.Net.NetworkCredential(username, pwd)
- End If
- wc.DownloadFile(uri, destFile)
- End Sub
- Function FileSize(ByVal url As String)
- Dim Request As System.Net.WebRequest
- Dim Response As System.Net.WebResponse
- Dim SizeFile As Integer
- Request = Net.WebRequest.Create(url)
- Request.Method = Net.WebRequestMethods.Http.Head
- Response = Request.GetResponse
- SizeFile = Response.ContentLength
- Return SizeFile
- End Function
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Timer1.Interval = 100
- If Timer1.Enabled = False Then
- Timer1.Enabled = True
- Else
- Timer1.Enabled = False
- End If
- Dim t As New System.Threading.Thread(AddressOf Me.DoDownload)
- t.Start()
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- Dim value1 As Integer
- Dim value2 As Integer
- Dim value3 As Integer
- value1 = getSize
- value2 = GetFileSize(TextBox2.Text)
- value3 = value2 / value1 * 100
- ProgressBar1.Value = value3
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement