|
-
Mar 7th, 2009, 02:51 AM
#1
Thread Starter
Addicted Member
Progress in URLDownloadToFile
How can I get Progress of downloaded files in URLDownloadToFile API?
If above question or answer will help to you
Don't forget to rate me
தமிழ்இன்பன்
-
Mar 7th, 2009, 08:43 AM
#2
Hyperactive Member
Re: Progress in URLDownloadToFile
-
Mar 7th, 2009, 10:08 AM
#3
Re: Progress in URLDownloadToFile
That program maybe OK as long as the file has a Content-Length associated with it but .HTML files do not.
EDIT AFTER POST:
I ran that program several times using different files to download. It downloads .TXT files OK and .HTML files OK (but no progressbar because .HTML files have no Content-Length). It does not download .EXE, .ZIP files correctly. The downloaded files are much smaller in size and are corrupted. If the file has no Content-Length (as in .HTML) you will get an error when it tries to move the progressbar because the file length is 0 and you will get a division by zero error.
Last edited by jmsrickland; Mar 7th, 2009 at 12:26 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 7th, 2009, 12:27 PM
#4
Re: Progress in URLDownloadToFile
Download with progress can be achieved easily with the WinHTTP library in asynchronous mode. Add reference to WinHTTP.dll in systems32. (Browse to it, if Microsoft WinHTTP services doesn't show on the references list.)
Note this simple example doesn't do anything fancy, just dumps the downloaded bytes to disk.
OnResponseStart when you can safely access the headers.
OnResponseDataAvailable which returns a byte array of downloaded data for each chunk.
OnResponseEnd which ends the download.
Code:
Option Explicit
Private WithEvents http As WinHttpRequest
Private mContentLength As Long
Private mProgress As Long
Private Sub Command1_Click()
' Create the WinHTTPRequest ActiveX Object.
Set http = New WinHttpRequest
' Open an HTTP connection.
http.open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg", True 'True means asynch.
' Send the HTTP Request.
http.send
End Sub
Private Sub http_OnResponseDataAvailable(Data() As Byte)
mProgress = mProgress + UBound(Data) + 1
ProgressBar1.Value = mProgress
Put #1, , Data
End Sub
Private Sub http_OnResponseFinished()
Close #1
MsgBox "done"
End Sub
Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
Text1.Text = http.getAllResponseHeaders()
mProgress = 0
mContentLength = CLng(http.getResponseHeader("Content-Length"))
ProgressBar1.Max = mContentLength
Open "C:\twg_gdo_1.mpg" For Binary As #1
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Mar 7th, 2009, 12:35 PM
#5
Re: Progress in URLDownloadToFile
Same situation. You are depending on Content-Length just like the first program.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 7th, 2009, 12:51 PM
#6
Fanatic Member
Re: Progress in URLDownloadToFile
With AJAX and Iframes how can you tell the Content length of html anyways?
-
Mar 9th, 2009, 09:00 AM
#7
Re: Progress in URLDownloadToFile
Don't know what AJAX is but I wouldn't think that the content length of an HTML file has anything to do with Iframes.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 9th, 2009, 12:09 PM
#8
Re: Progress in URLDownloadToFile
I follow Microsofts example when setting up a progress bar for downloading files.
I don't waste time with meaningless programming code trying to figure out what I should set as the max on my progress bar....I, like Microsoft, simply pull a number out of my hat and use that.
(PS: I'm not kidding...that is exactly what I do, and I'm convinced that is what Microsoft and others do as well.)
-
Mar 9th, 2009, 02:24 PM
#9
Fanatic Member
Re: Progress in URLDownloadToFile
is this what you want?
Code:
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Dim retVal As Long
Dim theUrl As String
Dim savePath As String
Dim pathExist As Long
Code:
Private Sub Command1_Click()
theUrl = "http://www.w3schools.com/index.html"
If theUrl = "" Then Exit Sub
savePath = App.Path + "/w3index.html"
If savePath = "" Then Exit Sub
retVal = URLDownloadToFile(0, theUrl, savePath, 0, 0)
If retVal = 0 Then
msgbox "success"
Else
msgbox "failed"
End If
End Sub
that url doesnt excist.
-
Mar 9th, 2009, 04:38 PM
#10
Re: Progress in URLDownloadToFile
 Originally Posted by Justa Lol
is this what you want?
Are you sure you are posting in the correct thread?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 10th, 2009, 06:19 AM
#11
Fanatic Member
Re: Progress in URLDownloadToFile
 Originally Posted by jmsrickland
Don't know what AJAX is but I wouldn't think that the content length of an HTML file has anything to do with Iframes.
Iframes us multiple clients to download nested content as for AJAX that's active content http://www.w3schools.com/Ajax/Default.Asp
-
Mar 10th, 2009, 07:19 AM
#12
Re: Progress in URLDownloadToFile
That still has nothing to do with the length of an HTML file.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 10th, 2009, 11:05 AM
#13
Fanatic Member
Re: Progress in URLDownloadToFile
Yes the length of the parent file is the same but the entire screen content is much larger since it is a hierarchy of html files. And with Ajax the content size since the internal html will change dynamically. Usually when you Iframe or use frames in general you root html is miniscule.
-
Mar 10th, 2009, 11:17 AM
#14
Re: Progress in URLDownloadToFile
That's my point. When you download an HTML file you are looking for the length of that file as it is in it's text state. What the internal elements do later (like make it bigger on the screen) is not relavent to it's original file length. That's why I stated I wouldn't think that the content length of an HTML file has anything to do with Iframes because it doesn't. The browser downloads the original HTML document then downloads the HTML that makes up the iFrame. Two different files.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Mar 10th, 2009, 04:35 PM
#15
Fanatic Member
Re: Progress in URLDownloadToFile
My point is: Whats the ultimate goal of tracking the progress on a bar. the 2seconds it takes to download the parent, or an indicator that all of the content has arrived?
-
Mar 10th, 2009, 05:42 PM
#16
Re: Progress in URLDownloadToFile
No, no, no. I think you are missing the point. The OP is not trying to do like a browser does and download all that is needed. The original question was
How can I get Progress of downloaded files in URLDownloadToFile API which suggests that he will download one file at a time with a progressbar for each downloaded file. But the browser downloads the main HTML and then begins to download all the images, iframe documents, etc, etc which the browser will include these in one progressbar download. These are two different things here. If this is not what the OP was suggesting then his 1st post is a little misleading then.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|