filename in exported excel file

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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" );
 
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
 
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.
 
Back
Top