Download status(webclient)

useless

Newcomer
Joined
Sep 22, 2003
Messages
3
Hi all

I want to know how can I get the size of the file being downloaded and the progress status so I can put it in a progress bar.


Code:

Dim web As New System.Net.WebClient()
web.DownloadFile("http://www.somethig.com", CurDir() & "\file.exe")


If someone knows I would be very thankfull

Thx in advanced..
 
yes, i too, need the answer. although does anybody have code so it like only downloads the certain file from a certain directory if it is a newer version of the program?
 
I found a function that works for me

just add a progress bar and you´r set
Visual Basic:
Function DownloadChunks(ByVal sURL As String, ByVal pProgress As ProgressBar, ByVal Filename As String) 
        Dim wRemote As System.Net.WebRequest 
        Dim URLReq As HttpWebRequest 
        Dim URLRes As HttpWebResponse 
        Dim FileStreamer As New FileStream(Filename, FileMode.Create) 
        Dim bBuffer(999) As Byte 
        Dim iBytesRead As Integer 

        Try 
            URLReq = WebRequest.Create(sURL) 
            URLRes = URLReq.GetResponse 
            Dim sChunks As Stream = URLReq.GetResponse.GetResponseStream 
            pProgress.Maximum = URLRes.ContentLength 

            Do 
                iBytesRead = sChunks.Read(bBuffer, 0, 1000) 
                FileStreamer.Write(bBuffer, 0, iBytesRead) 
                If pProgress.Value + iBytesRead <= pProgress.Maximum Then 
                    pProgress.Value += iBytesRead 
                Else 
                    pProgress.Value = pProgress.Maximum 
                End If 
            Loop Until iBytesRead = 0 
            pProgress.Value = pProgress.Maximum 
            sChunks.Close() 
            FileStreamer.Close() 
            Return sResponseData 
        Catch 
            MsgBox(Err.Description) 
        End Try 
    End Function
 
Last edited:
Back
Top