Connecting Tech Pros Worldwide Forums | Help | Site Map

Downloading file from web server

Richard L Rosenheim
Guest
 
Posts: n/a
#1: Nov 21 '05
I know that I can download a file from a web server by using the
WebClient.DownloadFile method. But, does anyone know of an example of
downloading a file from a web server with the ability to monitor the
download progress?

I'm looking for either the number of bytes downloaded and/or percentage
completed.

TIA



Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Nov 21 '05

re: Downloading file from web server


"Richard L Rosenheim" <richard@rlr.com> schrieb:[color=blue]
> But, does anyone know of an example of
> downloading a file from a web server with the ability
> to monitor the download progress?[/color]

<URL:http://groups.google.de/groups?q=dotnet+download+file+progress>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Richard L Rosenheim
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Downloading file from web server


Thanks, I found a Compact Framework example that looks promising. I should
be able to utilize the code, after possibly a little conversion.

Richard


"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:O01vU6cuEHA.3984@TK2MSFTNGP09.phx.gbl...[color=blue]
> "Richard L Rosenheim" <richard@rlr.com> schrieb:[color=green]
> > But, does anyone know of an example of
> > downloading a file from a web server with the ability
> > to monitor the download progress?[/color]
>
> <URL:http://groups.google.de/groups?q=dotnet+download+file+progress>
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>
>
>[/color]


Ken Tucker [MVP]
Guest
 
Posts: n/a
#4: Nov 21 '05

re: Downloading file from web server


Hi,

Here is a quick example. Add these import statements.

Imports System.Net

Imports System.IO



Sample code



Dim request As WebRequest

Dim response As WebResponse

Dim reader As Stream

Dim writer As Stream

Dim data(1023) As Byte

Dim count As Integer

Dim total As Integer

Me.Show()

Me.Text = "Downloading file ....."

Application.DoEvents()

request =
WebRequest.Create("http://www.onteorasoftware.com/downloads/multigrids.zip")

response = request.GetResponse()

reader = response.GetResponseStream()

ProgressBar1.Maximum = CInt(response.ContentLength)

ProgressBar1.Value = 0

total = 0

writer = File.Create("mylocaldata.zip")

While True

count = reader.Read(data, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(data, 0, count)

total += 1024

If total < ProgressBar1.Maximum Then ProgressBar1.Value = total

Application.DoEvents()

End While

reader.Close()

writer.Close()



Ken

--------------------------

"Richard L Rosenheim" <richard@rlr.com> wrote in message
news:uv3X0rcuEHA.2196@TK2MSFTNGP14.phx.gbl...
I know that I can download a file from a web server by using the
WebClient.DownloadFile method. But, does anyone know of an example of
downloading a file from a web server with the ability to monitor the
download progress?

I'm looking for either the number of bytes downloaded and/or percentage
completed.

TIA



Richard L Rosenheim
Guest
 
Posts: n/a
#5: Nov 21 '05

re: Downloading file from web server


Thanks.

Richard


"Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
news:ui%23AglduEHA.3200@TK2MSFTNGP14.phx.gbl...[color=blue]
> Hi,
>
> Here is a quick example. Add these import statements.
>
> Imports System.Net
>
> Imports System.IO
>
>
>
> Sample code
>
>
>
> Dim request As WebRequest
>
> Dim response As WebResponse
>
> Dim reader As Stream
>
> Dim writer As Stream
>
> Dim data(1023) As Byte
>
> Dim count As Integer
>
> Dim total As Integer
>
> Me.Show()
>
> Me.Text = "Downloading file ....."
>
> Application.DoEvents()
>
> request =
>[/color]
WebRequest.Create("http://www.onteorasoftware.com/downloads/multigrids.zip")[color=blue]
>
> response = request.GetResponse()
>
> reader = response.GetResponseStream()
>
> ProgressBar1.Maximum = CInt(response.ContentLength)
>
> ProgressBar1.Value = 0
>
> total = 0
>
> writer = File.Create("mylocaldata.zip")
>
> While True
>
> count = reader.Read(data, 0, 1024)
>
> If count <= 0 Then
>
> Exit While
>
> End If
>
> writer.Write(data, 0, count)
>
> total += 1024
>
> If total < ProgressBar1.Maximum Then ProgressBar1.Value = total
>
> Application.DoEvents()
>
> End While
>
> reader.Close()
>
> writer.Close()
>
>
>
> Ken
>
> --------------------------
>
> "Richard L Rosenheim" <richard@rlr.com> wrote in message
> news:uv3X0rcuEHA.2196@TK2MSFTNGP14.phx.gbl...
> I know that I can download a file from a web server by using the
> WebClient.DownloadFile method. But, does anyone know of an example of
> downloading a file from a web server with the ability to monitor the
> download progress?
>
> I'm looking for either the number of bytes downloaded and/or percentage
> completed.
>
> TIA
>
>
>[/color]


Closed Thread