L
Loane Sharp
Hi there
I'm attempting to download a file from our server programmatically using an
internet connection. Ordinarily I would use WebClient.DownloadFile() but I
would like to show a progress bar during the download.
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()
I'm attempting to download a file from our server programmatically using an
internet connection. Ordinarily I would use WebClient.DownloadFile() but I
would like to show a progress bar during the download.
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()