473,395 Members | 1,539 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,395 software developers and data experts.

How to specify Mime filename in ASP page?

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
1 4327
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas Williams | last post by:
Hello everyone, my name is Tom W. And, I am new to the list, and have been using Python for about a year now. Anyway, I got a question! I am trying to decode MIME (base64) email from a POP3...
1
by: Luis | last post by:
I have a few input buttons at the end of an asp page. When I change the mime-type of the asp page to create a Word Document which the user can save, the input buttons are not displayed. Is there a...
0
by: mizi | last post by:
I am writing an ASP page for downloading some files, such as jpg, doc which are known MIME type. I want to force user save these files through a "file download" dialog instead of open them on the...
1
by: ad | last post by:
I use the code below to export the content of a data set to Excel, the code come form http://www.dotnetjohn.com/articles.aspx?articleid=36 But it always use the web form's name as the default...
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
3
by: LordHog | last post by:
Hello, How would I go about finding the default handler, let's say a text file (*.txt), then launch the default handler with the file as an argument? I had found how to launch an external...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.