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

How to specify Mime filename in ASP page?

P: n/a
SW
I have an ASP page that causes Excel to be loaded on the client PC
with the text sent from within the page. An excerpt of it is shown
below:

With Response
.ContentType = "application/vnd.ms-excel"
.Write(strResponse)
.Flush
.End
End With

where strResponse is the text to be displayed in Excel.

This all works fine and as expected, but the only problem is that the
file is opened in Excel on the client with a filename that reflects
the page from which the information originated, e.g:

http://myserver/mypage.asp

Is there any way of specifying the filename using MIME, for example if
I wanted the file to be loaded in Excel as "myfile.xls"?

Many thanks in advance
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You need to add the Content-Disposition header:

Response.AddHeader "content-disposition", "inline; filename=""" &
server.URLPathEncode("MyFileName.csv") & """"

There is a small bug in IE's handling of content-disposition. The choices
are "inline" or "attachment"... but if the word attachment appears anywhere
in the header's value then the response will be treated as an attachment. So
the following would force the user to save the file:
Response.AddHeader "content-disposition", "inline; filename=""" &
server.URLPathEncode("Attachment.csv") & """"

I work around this by replacing the word Attachment with Attachmnt... not
great... but it does solve the problem.

Also be careful about extra periods in the filename. It seems a filename
like "a.b.txt" comes out at "a.b.txt[1]", but if you escape the first period
then things work: "a%2eb.txt" comes out as "a.b.txt". I use the following:
strfilename = replace(left(strfilename, instr(1, strfilename, "." &
fso.GetExtensionName(strFilename)) - 1), ".", "%2e") & "." &
fso.GetExtensionName(strFilename)

Not very elegant... but it does work.

Regards,

Rob
--
RMTrack a new bug tracking tool. Available now from www.rmtrack.com (watch
for our new 1.2 release!)
"SW" <s.******@talk21.com> wrote in message
news:65**************************@posting.google.c om...
I have an ASP page that causes Excel to be loaded on the client PC
with the text sent from within the page. An excerpt of it is shown
below:

With Response
.ContentType = "application/vnd.ms-excel"
.Write(strResponse)
.Flush
.End
End With

where strResponse is the text to be displayed in Excel.

This all works fine and as expected, but the only problem is that the
file is opened in Excel on the client with a filename that reflects
the page from which the information originated, e.g:

http://myserver/mypage.asp

Is there any way of specifying the filename using MIME, for example if
I wanted the file to be loaded in Excel as "myfile.xls"?

Many thanks in advance

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.