By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

Generating a "virtual file"

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try :

http://support.microsoft.com/kb/260519/en-us

"fname.ext" allows to indicate the name you want to show client side...

Patrice

--

"Mark Rendle" <markdotrendleatcomputersoftwaredotcom> a écrit dans le
message de news:ue*************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #2

P: n/a
"Mark Rendle" <markdotrendleatcomputersoftwaredotcom> wrote in message news:ue*************@tk2msftngp13.phx.gbl...
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
Nov 19 '05 #3

P: n/a

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

Response.AddHeader "Content-Disposition", "attachment; filename=" &
SaveFileName
"Mark Rendle" <markdotrendleatcomputersoftwaredotcom> wrote in message
news:ue*************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #4

P: n/a
Thanks all for the quick response. Works a treat!

Mark
Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.