Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. Public Class Form1
  2. Private getSize = Me.FileSize(TextBox1.Text)
  3. Private Function GetFileSize(ByVal MyFilePath As String)
  4. Dim fileDetail As IO.FileInfo
  5. fileDetail = My.Computer.FileSystem.GetFileInfo(MyFilePath)
  6. Return fileDetail.Length
  7. End Function
  8. Sub DoDownload()
  9. DownloadFile(TextBox1.Text, TextBox2.Text)
  10. End Sub
  11. Sub DownloadFile(ByVal uri As String, ByVal destFile As String, _
  12. Optional ByVal username As String = Nothing, Optional ByVal pwd As String = _
  13. Nothing)
  14. Dim wc As New System.Net.WebClient
  15. If Not username Is Nothing AndAlso Not pwd Is Nothing Then
  16. wc.Credentials = New System.Net.NetworkCredential(username, pwd)
  17. End If
  18. wc.DownloadFile(uri, destFile)
  19. End Sub
  20. Function FileSize(ByVal url As String)
  21. Dim Request As System.Net.WebRequest
  22. Dim Response As System.Net.WebResponse
  23. Dim SizeFile As Integer
  24.  
  25. Request = Net.WebRequest.Create(url)
  26. Request.Method = Net.WebRequestMethods.Http.Head
  27.  
  28. Response = Request.GetResponse
  29. SizeFile = Response.ContentLength
  30. Return SizeFile
  31. End Function
  32. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  33. Timer1.Interval = 100
  34. If Timer1.Enabled = False Then
  35. Timer1.Enabled = True
  36. Else
  37. Timer1.Enabled = False
  38. End If
  39. Dim t As New System.Threading.Thread(AddressOf Me.DoDownload)
  40. t.Start()
  41. End Sub
  42.  
  43. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  44. Dim value1 As Integer
  45. Dim value2 As Integer
  46. Dim value3 As Integer
  47. value1 = getSize
  48. value2 = GetFileSize(TextBox2.Text)
  49. value3 = value2 / value1 * 100
  50. ProgressBar1.Value = value3
  51. End Sub
  52. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement