By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,889 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,889 IT Pros & Developers. It's quick & easy.

GetResponseStream() fails

P: n/a
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()
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


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

"Loane Sharp" <lo************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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()

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.