CoverYourASP --> Snippets

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
47 active users
1035 visitors today
962 pages today
how is this done?
Tools I use

Copyright © 1999-2016 James Shaw.
All rights reserved.

RSS submissions

Now open source with SourceForge!

"Snippets" are mini-articles - they allow me to very quickly add answers to your frequently asked questions, and add brief explanations for topics that you've searched for without success. So, everytime you send an email or perform a search, chances are a new snippet will be the result!

10 Oct: Auto-downloads using Response.AddHeader

Recently I was writing a page for a customer that has a lot of programs that you can download demonstration versions of. The plan was to show some instructions about how to install the demo and have the download start automatically after a few seconds.

To do this I called Response.AddHeader to tell the browser to reload the zip file after 3 seconds. zip files are usually handled by the browser displaying a File Download dialog box allowing you to run or save the file to disk.

Here's how it works:

Response.AddHeader ( 'Refresh', '3; URL=' + sName + '.zip' );

I had retrieved the name of the download from the database and placed it in the sName variable before the call.

You must specify an absolute URL - not a relative path to the file on the server. Remember, this will be acted upon by the browser on the client-side, not by the server.

Headers can only be added in this way if Response buffering is enabled. This is the default in IIS 5.0, but it's safer to add the following line to the top of your page to be sure. (In the CYA code this line is part of the include/startup.asp file that is included in every page):


Featured sponsor
My favorite resources

Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?