Solved

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

Posted on 2004-04-29
1
695 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
1 Comment
 
LVL 49

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Read about why website design really matters in today's demanding market.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now