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 wocould be very thankfull THX in advanced ..
Edited by-useless on 9/25/2003 1:04:22 |
|
|
|
#1Re: Download Status (WebClient) |
|
reply |
W/quote |
B 'mark-it! |
edit |
Del |
|
|
|
(Addicted Member)
Posts106 Since: Aug 31,200 3 From: Iceland |
This reply is rated1Point. |
|
Well after hrs of search I found the answer and here it is for you all .. Code: 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 |
|
Http://www.vbcity.com/forums/topic.asp? Tid = 41354
|
|
#2Re: Download Status (WebClient) |
|
reply |
W/quote |
B 'mark-it! |
edit |
Del |
|
|
|
(New member)
Posts: 2 Since: Jul 13,200 4 From: USA |
This reply is rated3Points. |
|
Quote: PostedUselessOn 9/23/2003 2:20:01 am (PST ): Well after hrs of search I found the answer and here it is for you all .. Code: 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 Your VB. NET code is pure genius It's the only one that seems to work, but... do you also know anything about C #? I was trying to convert that VB code to C #, But I 've ran into one problem. :-/ Herb |
|
|
|
#3Re: [resolved] Download Status (WebClient) |
|
Reply |
W/quote |
B 'mark-it! |
Edit |
Del |
|
|
|
(New member)
Posts: 2 Since: Jul 13,200 4 From: USA |
This reply is rated3Points. |
|
It's a lot different in C # Code: Private bool downloadfile (string Surl, progressbar pProgress, string filename) { System. net. httpwebrequest urlreq; System. net. httpwebresponse urlres; System. Io. filestream filestreamer; Byte [] bbuffer = new byte [999]; Int ibytesread = 0; Try { Filestreamer = new filestream (filename, system. Io. filemode. Create ); Urlreq = (httpwebrequest) system. net. webrequest. Create (Surl ); Urlres = (httpwebresponse) urlreq. getresponse (); Stream schunks = urlreq. getresponse (). getresponsestream (); PProgress. Maximum = convert. toint32 (urlres. contentlength ); PProgress. Visible = false; Do { Ibytesread = schunks. Read (bbuffer, 0, 1000 ); Filestreamer. Write (bbuffer, 0, ibytesread ); If (pProgress. Value + ibytesread <= pProgress. Maximum) { PProgress. Value + = ibytesread; } Else { PProgress. value = pProgress. maximum; } } While (ibytesread! = 0 ); PProgress. value = pProgress. maximum; Schunks. Close (); Filestreamer. Close (); Return true; } Catch (exception ee) { MessageBox. Show (EE. Message ); Return false; } } |
|
|
|
#4Re: [resolved] Download Status (WebClient) |
|
Reply |
W/quote |
B 'mark-it! |
Edit |
Del |
|
|
|
( new member )
posts : 1 since : Mar 23,200 5 |
This reply is rated 3 points. |
|
Hi all, I have noticed that the script doesn't work with small files. it works only with files with a lot of megabytes. somebody can help me to modify the code for run it also on small file? I work on C # thanks a lot! |
|