Download in Cache

N

NevilleT

I am trying to download a text file from a web site using the following code.

'--------------------------------------------
' Get the file from the Internet
If funIsNetConnected = True Then ' Check for an Internet
connection
lngRetVal = URLDownloadToFile(0, strTextFileURL, strLocalTextFile,
0, 0)
' Download the new file. If successful lngRetVal = 0
DoEvents
Else
GoTo Exit_subGetVersion ' No
Internet connection so exit.
End If

I am using a function (funIsNetConnected) to check for a connection to the
net.
strTextFileURL is the path to the file on the net. Once downloaded, the
text file contains the latest version and build number which I use to see if
there is an update to the program available.

The file seems to download without a problem however I am getting an old
version of the text file. In other words, if I change the text file on the
server, I still download the old version. I suspect somewhere it is being
cached, and rather than download the file, it is pulling a copy from a cache.
The speed at which the download occurs would confirm this. I have tried
deleting the file after I read it using

fso.DeleteFile (strLocalTextFile)

Has anyone had a similar experience with URLDownloadToFile and is there a
way to clear a cache before downloading?
 
D

Dirk Goldgar

NevilleT said:
I am trying to download a text file from a web site using the following
code.

'--------------------------------------------
' Get the file from the Internet
If funIsNetConnected = True Then ' Check for an Internet
connection
lngRetVal = URLDownloadToFile(0, strTextFileURL, strLocalTextFile,
0, 0)
' Download the new file. If successful lngRetVal = 0
DoEvents
Else
GoTo Exit_subGetVersion ' No
Internet connection so exit.
End If

I am using a function (funIsNetConnected) to check for a connection to the
net.
strTextFileURL is the path to the file on the net. Once downloaded, the
text file contains the latest version and build number which I use to see
if
there is an update to the program available.

The file seems to download without a problem however I am getting an old
version of the text file. In other words, if I change the text file on
the
server, I still download the old version. I suspect somewhere it is being
cached, and rather than download the file, it is pulling a copy from a
cache.
The speed at which the download occurs would confirm this. I have tried
deleting the file after I read it using

fso.DeleteFile (strLocalTextFile)

Has anyone had a similar experience with URLDownloadToFile and is there a
way to clear a cache before downloading?


This link seems to address the caching problem with URLDownloadToFile:

http://vbnet.mvps.org/index.html?code/internet/urldownloadtofilenocache.htm
URLDownloadToFile: Fast, Simple and Transparent
File Downloads Bypassing the IE Cache

The code is for VB, not Access VBA, but should be easily adaptable.
 
N

NevilleT

Thanks Dirk. Just needed to include the DeleteUrlCacheEntry That fixed it.I
have a nice little version upgrade advice and automatic update function
working now. I must put it all together into a sample program others can
use. Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top