?
Solved

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

Posted on 2004-04-29
1
Medium Priority
?
848 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 53

Accepted Solution

by:
Ryan Chong earned 500 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
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).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

771 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