Results 1 to 13 of 13

Thread: URLDownloadToFile is not d/l updated file

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,602

    URLDownloadToFile is not d/l updated file

    Hey All. I'm using URLDownloadtoFIle to go online and d/l a series of pages to view offline. But I think instead of d/l fresh copies, it may be taking them from temporary internet files.

    Whenever I give it a new page to download, it will take about 30 seconds to download but whenever I give it an already used URL, it downloads in less than a second. Seems fishy.

    Is there a way to force it to make a fresh download?

    This is the code I've been using:

    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

    Private Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
    End Function

    maybe it's one of the last two parameters?

    Thanks
    Wengang
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    It's not the last two parameters; the second last param is reserved (unused at the moment) so you have to set it to 0. The last param is a pointer to an IBindStatusCallback interface, which is for progress notification, so isn't relevant to the problem.

    To avoid the system using cached copies, I guess you'd have to either clear the temporary files before the call, or download the file manually with winsock.
    an ending

  3. #3

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,602
    So, if I am using URLDownloadtoFile, is it not directly storing the HTML in a file? I thought this way, it would not have a cached file/temporary file.

    I used to use INET for this but is too unreliable.

    Can also put the file into a webbrowser control, but have never been able to figure out the .innerHTML thing, to save the page to file

    I have never used winsock. Is it complicated, just for downloading an html file?

    Thanks
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  4. #4
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    URLDownloadToFile is pat of the shell/IE API, so I'd imagine it would make use of the cache.

    Using winsock wouldn't be particularly complicated, just connect to the host, send a HTTP request, and wait for the server to send all the data. Look up the HTTP specification.
    an ending

  5. #5

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,602
    yes, I assumed as much. I know in IE options there is an option on how often to seek a fresh copy of frequently viewed pages, so I gathered it was imitating that behavior.

    I just haven't used Winsock before. have seen a lot of posts on this forum over the years concerning Winsock issues. Wonder if it is problematic??
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  6. #6
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Winsock works perfectly well if used correctly It's not a trivial topic, but isn't particularly complicated unless you want to get into high-performance server writing or something.
    an ending

  7. #7
    New Member
    Join Date
    Sep 2013
    Posts
    5

    Re: URLDownloadToFile is not d/l updated file

    I am trying to do the same thing in my mac and it does not seem to work.
    I get a return value of 0 and no errors
    How do you pass the localfilename?
    Maybe thats the issue in my case? please let me know

    Thanks
    Anita


    Quote Originally Posted by wengang View Post
    Hey All. I'm using URLDownloadtoFIle to go online and d/l a series of pages to view offline. But I think instead of d/l fresh copies, it may be taking them from temporary internet files.

    Whenever I give it a new page to download, it will take about 30 seconds to download but whenever I give it an already used URL, it downloads in less than a second. Seems fishy.

    Is there a way to force it to make a fresh download?

    This is the code I've been using:

    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

    Private Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
    End Function

    maybe it's one of the last two parameters?

    Thanks
    Wengang

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: URLDownloadToFile is not d/l updated file

    call clearcache first
    Code:
    Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
       Alias "DeleteUrlCacheEntryA" _
      (ByVal lpszUrlName As String) As Long
    'call like
       Call DeleteUrlCacheEntry(sSourceUrl)
    there is a parameter, but i am not sure it is fully supported
    Last edited by westconn1; Sep 26th, 2013 at 04:41 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    New Member
    Join Date
    Sep 2013
    Posts
    5

    Re: URLDownloadToFile is not d/l updated file

    Quote Originally Posted by westconn1 View Post
    call clearcache first
    Code:
    Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
       Alias "DeleteUrlCacheEntryA" _
      (ByVal lpszUrlName As String) As Long
    'call like
       Call DeleteUrlCacheEntry(sSourceUrl)
    there is a parameter, but i am not sure it is fully supported
    I get this error - File not found, Wininet.dll
    Is this not supported for mac?

    Anitha

  10. #10
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: URLDownloadToFile is not d/l updated file

    Quote Originally Posted by anithacd View Post
    I get this error - File not found, Wininet.dll
    Is this not supported for mac?

    Anitha
    Well, considering that VB6 is Windows only software it should be installed on Windows, not sure why that file is complaining (can not remember if it was installed with VB6 or as part of the operating system)?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: URLDownloadToFile is not d/l updated file

    are you doing this in vb6 or some office application?

    i try to know less than nothing about macs
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12
    New Member
    Join Date
    Sep 2013
    Posts
    5

    Re: URLDownloadToFile is not d/l updated file

    Thanks for your reply
    This is for a VB macro in Excel Mac 2011.
    The visual basic version is 14.3.6
    All I want is to get images from a windows server and display in xl; But Shapes.Addpicture does not work with mac.
    So I am trying to get it through an http Url, save it in a local directory and display from there
    Thanks
    Anitha


    Quote Originally Posted by westconn1 View Post
    are you doing this in vb6 or some office application?

    i try to know less than nothing about macs

  13. #13
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: URLDownloadToFile is not d/l updated file

    @ anithacd

    See my reply in your other thread.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

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