GetResponseStream() fails

L

Loane Sharp

Hi there

I'm attempting to download a file from our server programmatically using an
internet connection.

The code is given below.

Any ideas why it fails?

Best regards
Loane

[Other info: "pbr" is a progress bar initiated earlier in the code]

Dim fs_App As FileStream = New FileStream("C:\mainapp.zip", FileMode.Create)
datBuffer = New Byte(1023) {}
Dim reqSync_App As WebRequest =
WebRequest.Create("http://www.123.com/mainapp.zip")
Dim respSync_App As WebResponse = reqSync_App.GetResponse()
Dim strm_App As Stream = respSync_App.GetResponseStream()
Dim len_App As Double
Dim total, cnt_App As Integer
While total < pbrSync.Maximum
cnt_App = strm_App.Read(datBuffer, 0, 1024)
If cnt_App <= 0 Then Exit While
fs_App.Write(datBuffer, 0, cnt_App)
total += cnt_App
If total < pbrSync.Maximum Then pbrSync.Value = total
lblInfo7b.Text = "Downloading application file ... (" &
(total/1024).ToString("#,##0") & "KB of " &
(pbrSync.Maximum/1024).ToString("#,##0") & "KB) (" &
((total/1024)/(pbrSync.Maximum/1024)*100).ToString("##0") & "%)"
Application.DoEvents()
End While
respSync_App.Close()
strm_App.Close()
fs_App.Close()
 
L

Loane Sharp

P.S. The webclient.downloadfile method works great, but I need a progress
bar ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top