filename in exported excel file

G

Guest

I checked a few sites on exporting data from asp.net to excel and most of them point to the same source a
http://support.microsoft.com/default.aspx?scid=kb;EN-US;317719 with some modifications

My code is in the block below. When I click save when the open/save message box pops up, the file is saved as the aspx page's name with .xls. However, when I open the file, the filename is the exact aspx page name with .aspx in MS Excel

Response.Buffer = true
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
this.EnableViewState = false
//Response.AddHeader("Content-Disposition", "filename=Data.xls;"); // set the filenam
Response.Write("something")

Response.End()

I tried to set the filename by Response.AddHeader. When I do a save, the filename is saved as the specified .xls. However, when I open the file from the open/save popup, the filename is still the aspx page's name

I am wondering what could be wrong and how to fix this

Thank you

Zud
 
K

Ken Cox [Microsoft MVP]

Hmmm ... Shouldn't you be including "attachment" in there? Don't forget to
clear the preceding content:

Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.ContentType = "Application/x-msexcel";
Response.AppendHeader("content-disposition", "attachment;
filename=Data.xls" );
 
G

Guest

Hi, Ken

"attachment" kind of worked. For all the additions you relied, only the "attachment" made the opened excel file has the data[1].xls.

However, I need to click the Open button twice to open it when the open/save message box popped up and I think this is because it was attaching the first time I clicked and the second click opened it up

Are there any other attributes or properties need to be set to open the file by only clicking one

Thank you

Zude
 
S

Scott

This business about having to click Open twice is a bug in IE; the only way around it that I know,
involves changing/creating a new page with the appropriate file name extension and avoiding the
attachment option.

There was a thread about the a week or so ago.

Scott

zweng said:
Hi, Ken,

"attachment" kind of worked. For all the additions you relied, only the "attachment" made the
opened excel file has the data[1].xls.
However, I need to click the Open button twice to open it when the open/save message box popped up
and I think this is because it was attaching the first time I clicked and the second click opened it
up.
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top