Solved

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

Posted on 2004-04-29
1
671 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
Comment Utility
>>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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

15 Experts available now in Live!

Get 1:1 Help Now