[thelist] CSV file download on the fly with SQL/ASP generated pages - but how?

Jason Handby jasonh at corestar.co.uk
Tue Dec 30 07:00:32 CST 2003


Hi John,


> I am trying to create a "download this page as a csv file"
> facility for some of our internal reporting pages.  We are
> pulling the pages from SQL with ASP making a table from the information.
>
> Ideally there would be a link on the page which would initiate a download.
>
> I tried erroneously to embed some asp in a csv file, but it would
> open the CSV in an embedded spreadsheet in the browser.
>
> Does anyone have any ideas, or know how I can achieve this?

Write an ASP page that produces your CSV file as output. Call it
whatever.asp (in other words, name it .asp rather than .csv, otherwise IIS
won't know that it has to process it).

Then you need to hint to the browser that it should download the file as a
CSV rather than open it. And you can do this by adding the following near
the top of your ASP:

  Response.AddHeader "content-disposition", "attachment;
filename=whatever.csv"

(replacing whatever.csv with whatever filename you want it to have when it
downloads)


Hope this helps




Jason



More information about the thelist mailing list