Thanks! That did exactly what I needed.
Main Topics
Browse All TopicsSo I have a generic reporting tool that users can use to run reports against our database. They enter some input on a simple form or two, and the reporting tool takes that input and generates a complex SQL statement. The SQL statement is executed and the results are displayed in an HTML table.
Fine. My users, however, have requested that they want to be able to save the data in an Excel spreadsheet, so they can generate charts, for instance.
I can easily create a .CSV file and redirect the Response to that .CSV file -- but this is not what I want to do. Some of the .CSV files would be *huge*, hundreds of thousands of rows, so there would be two very lengthy phases: 1, create the .CSV by iterating over every row in the record set; and 2, upload every row in the record set to the client.
I just want 1 phase. I want to send the database data in CSV format directly to the user, without saving it in an intermediate file first.
I can set the content type to text/csv, which will prompt the user to Open/Save. But the filename will be wrong. (It would be something like Upload.asp).
My question is, Can I set the filename in a response header or something? It seems like this should be really obvious but I haven't found a way to do it.
Help is appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: apolloisPosted on 2002-11-23 at 16:18:32ID: 7488363
Add the following at the top of your ASP:
Response.contenttype = "text/csv"
Response.AddHeader "Content-Disposition", "attachment; filename=somefile.csv"
This should do it.
Best Regards,
Jim