Solved

why the function URLDownloadToFileA of (urlmon) doesn't work on  my computer ?

Posted on 2004-04-29
1
806 Views
Last Modified: 2012-08-14
I downloaded couple of program samples from sites in the internet &
they included a call to URLDownloadToFileA.

it works for me only if I'm downloading an http link which is already in the cache of my computer.
but if it isn't, it simple doesn't work...

I tested a page that I already downloaded using webBrowser control & I managed to save it
on the disk, but otherwise if I didn't navigate to it already, I didn't manage to download it...

help please !
0
Comment
Question by:MagicianH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 125 total points
ID: 10952086
>>it works for me only if I'm downloading an http link which is already in the cache of my computer.
but if it isn't, it simple doesn't work...
It Should works, btw, you're right, if there is a cache found, URLDownloadToFileA actualy is get the file from cache instead. However, it should also works if there is No cache found.

To remove the cache, we can have 2 solution.

1st, put a random key at the end of the URL when you use URLDownloadToFileA API to download the file.

like:

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

Public 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

Private Sub Form_Load()
   randomize
   key = int(rnd * 1000000)
    DownloadFile "http://www.yourdomain.com/myfile.asp?rnd=" & key, "c:\test.htm"
   msgbox "done!"
End Sub

2nd, apply DeleteUrlCacheEntry API just before you call URLDownloadToFileA .

Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long

like:

...
DeleteUrlCacheEntry "http://www.yourdomain.com/myfile.asp"
DownloadFile "http://www.yourdomain.com/myfile.asp", "c:\test.htm"
...

Hope this helps
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question