Generating a "virtual file"

M

Mark Rendle

Hi

I'm writing a page which outputs CSV data for download. It's all working
fine, setting ContentType to "text/csv", except when the "Open/Save" dialog
appears, the filename shown is "ExportRun.aspx". Is there any way I can
change this to, e.g., "mydata.csv" without having to generate a temporary
file on the server?

Thanks
Mark
 
D

Derek Harmon

Mark Rendle said:
setting ContentType to "text/csv", except when the "Open/Save" dialog appears, the filename shown is "ExportRun.aspx". Is there
any way I can change this to, e.g., "mydata.csv" without having to generate a temporary file on the server?

Mark,

You need to call AddHeader( ) on the Response to add the "Content-Disposition"
HTTP header and specify a filename (its not one of the standard HTTP headers
that ASP.NET exposes as a property on the HttpResponse class so you have to
use this general-purpose add-a-header method),

Response.AddHeader( "Content-Disposition",
String.Format( "attachment; filename=\"{0}\"",
"mydata.csv"
)
);

Watch letting users enter a value for this filename directly, though, since you're
writing it back out to the HTTP protocol's headers (a hacker could easily craft
a malformed header).


Derek Harmon
 
S

Steve Powell

just add this line to the header
(sample in asp)

Response.AddHeader "Content-Disposition", "attachment; filename=" &
SaveFileName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top