[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Stop cache of downloaded file

Hi,

Is there a way to stop the browser caching a downloaded file.

The file is a .xls (Excel) file and is updated regularly during the session. It's part of an ASP application and the user gets a distinct file name for the session.

The problem is that when the user clicks on the link the browser doesn't download the file, it just gets it from cache.

The link looks like this:
<a TITLE="Show results in Excel" HREF="<%=Session("UserFile")%>"><img SRC="../images/toexcel.gif" HEGHT="35" WIDTH="36" BORDER="1"></a>

Session("UserFile") = ../Excel/WD245365367.xls
the number is the Session.SessionId value.

I've tried using:
<meta http-equiv=pragma content=no-cache>
on the page that contains the link but that only stops the page from caching not the file.

I need to use the same filename all the time because when the session ends I want to delete it, otherwise the files would build up on the server.

Any tips?

/DH
0
doghund
Asked:
doghund
  • 4
  • 3
1 Solution
 
binkzzCommented:
If this is done internally, you might want to get the user to disable the caching client-side.
0
 
doghundAuthor Commented:
Thanks binkzz,

Asking the user to disable caching would solve the problem but it makes the application clumsy and unfriendly.
Not to mention that some users might not know how to change their browser settings (even with instructions they mightn't dare).
I have a backup plan invisible to the user just a little bit of extra code.

I can keep a count of the files the user asks for and each file can be called <Sessionid> & <count> & ".xls"
Then in the Session_onEnd I can loop through 1 to count and delete the files.
Messy, but it'll work.

Im going to have to implement this on Monday so if I can't find a better way it'll be 'Plan B' for me.
0
 
binkzzCommented:
If you're feeling adventurous, you could even modify the script by adding a subroutine that will output the file to the browser in uuencoding.

This way, it will get it from the script, which means it's never going be cached and you can have the filename set to whatever you want.

Another option would be that you would keep the filename of the excel file the same, but zip it up under a different (unique) filename.

Mcbee
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
doghundAuthor Commented:
The first idea sounds good because the user sees it straight away. Sending a zip file means extra work for him/her. Plus I'd still have to get rid of the zip files from the server.

I don't know anything about uuencoding.
Does it work on Explorer and Netscape?
Can the user save the file directly in the .xls format?
Can it be opened in a new sepatrate browser window?

If the answer to all 3 questions is YES, where can I find out more about it (quick 'n easy web tutorials etc.)?
0
 
binkzzCommented:
The first is also the best idea, but a lot harder to execute. You will find an ASP component on http://asp.superexpert.com/softwarelist/16.html that will allow you to uuencode and uudecode files.

Uuencoding is a reasonably old protocol, and will go back to the version 3 browsers as well, so you won't need to worry about compatibility issues.

If you do it this way, you can save the file directly in the .xls format, and you can have it so that it opens in a different browser, if you wanted to. You shouldn't need to do that, because what basically happens is that when they click on the page, the download commences. As far as I can remember, the page and it contents aren't interrupted by the download.

But if you want it in a seperate browser window, you can have it in a seperate browser window ;)

Mcbee

0
 
doghundAuthor Commented:
Sounds perfect.

Thanks for your time.
Just lock the question and the points are yours

/DH
0
 
binkzzCommented:
Thank you very kindly ;)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now