2007-04-11

Downloding progress of HTTPWebRequest

Dim Req As Net.HttpWebRequest = Net.WebRequest.Create(FilePath & FileName)
            Dim Res As Net.HttpWebResponse = Req.GetResponse
            Dim TotalSize As Integer = Res.ContentLength
            PB.Maximum = TotalSize
            Dim st As IO.Stream = Res.GetResponseStream
            Dim so As IO.Stream
            so = New IO.FileStream(FolderPath & FileName, IO.FileMode.Create)
            Dim DownloadedByte As Integer = 0
            Dim by(1024) As Byte
            Dim osize As Integer = st.Read(by, 0, by.Length)
            While osize > 0
                DownloadedByte = osize + DownloadedByte
                Application.DoEvents()
                so.Write(by, 0, osize)
                PB.Value = DownloadedByte
                LabelInfo.Text = DownloadedByte & " / " & TotalSize
                LabelInfo.Refresh()
                osize = st.Read(by, 0, by.LongLength)
            End While
            so.Close()
            st.Close()

沒有留言:

張貼留言