Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim wr As HttpWebRequest = CType(WebRequest.Create("http://www.mysite.com/dl.php"), HttpWebRequest)
Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
Dim str As Stream = ws.GetResponseStream()
Dim inBuf(10000000) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0
While bytesToRead > 0
Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
End If
bytesRead += n
bytesToRead -= n
MsgBox(bytesRead & " : " & bytesToRead)
Me.ProgressBarAdv1.Value = Math.Round(100 * bytesRead / n, 0)
Application.DoEvents()
End While
Dim fstr As New FileStream("C:\Data2\dl\ms1.zip", FileMode.OpenOrCreate, FileAccess.Write)
fstr.Write(inBuf, 0, bytesRead)
str.Close()
fstr.Close()
End Sub
|