473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Generating a "virtual file"

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
4 1362
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
"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

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
Thanks all for the quick response. Works a treat!

Mark
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: cppaddict | last post by:
Hi, I know that it is illegal in C++ to have a static pure virtual method, but it seems something like this would be useful when the following 2 conditions hold: 1. You know that every one...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
164
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
8
by: Asfand Yar Qazi | last post by:
Hi, I have the following header file in my 'everything useful I think of in one place' library: ============= BEGIN CODE SNIPPET =========== /** All classes that derive from this obtain a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.