Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
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…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

609 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