C and S Design.
Search Friendly Programming and Design

Go to -> C and S Design -> Articles -> Code -> ASP -> File Download -> Show Code

Click here to view or download the code for this example


File Download

ASP Force File Download

Save Open Dialog

One issue that faces programmers is how to allow users to download files and force the a file Open/Save dialog box to appear and bypass the browser "helper objects" that allow certain types of files to be viewed in the browser. For this site the problem is that most of the files would normally be parsed by the server before being delivered to the browser, so by creating a link to the asp file containing the code, would not generate a download but would simply send some output to the user agent.

The way that user agents determine how to handle file types is in the response headers sent from the server, so to work around this the server has to send a set of headers that identify the file not as any particular file type, but as the generic application/octet-stream. Browsers should identify this as purely as data and elicit the most appropriate response from the user rather than trying to determine the action from the filetype.

This code is designed to take a filename sent as a querystring parameter that will tell the download routine where the file is. This could easily be modified to take an identifying code and pull the file location from a database. This would then avoid exposing the dowmload path to users so could be used for paid downloads or members only files.


Valid HTML 4.01! Valid CSS! copyright © C and S Design 2004 - 2005
Website Design and SE Friendly Coding C and S Design