Results 1 to 16 of 16

Thread: Progress in URLDownloadToFile

  1. #1

    Thread Starter
    Addicted Member thamizhinpan's Avatar
    Join Date
    Dec 2005
    Location
    TE
    Posts
    243

    Question 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
    தமிழ்இன்பன்

  2. #2
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Progress in URLDownloadToFile


  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  4. #4
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  6. #6
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: Progress in URLDownloadToFile

    With AJAX and Iframes how can you tell the Content length of html anyways?
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.)

  9. #9
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    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.

  10. #10
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Progress in URLDownloadToFile

    Quote 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.

  11. #11
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: Progress in URLDownloadToFile

    Quote 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
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  12. #12
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  13. #13
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    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.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  14. #14
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  15. #15
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    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?
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  16. #16
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
  •  



Click Here to Expand Forum to Full Width