Can I change the response URL to http://server/page.XLS instead of http://server/page.ASPX ?

G

guillermojco

Hi,

I've got an ASP.NET page that returns XLS, DOC, PDF and other files
from binary fields in a database.

The problem is that MS-Excel 2007 shows a security warning when trying
to open the file because its name is page.ASPX instead of page.XLS
(the file opens properly when this warning is accepted by the user).

I thing the problem would solve if I can change the response URL from
"page.ASPX" to "page.XLS"

I don't want to use redirection because I don't have a real XLS file
but a byte array.

I've been unable to find this in the "Response" object documentation,
I wonder if it is possible.

Also, I don't have this problem with DOC or PDF files, they're opened
properly without any warnings.

Thanks!

Guillermo.
 
R

Ray Costanzo

This works for me:

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader ("Content-Disposition", "inline;
filename=somefile.xls");
}

Ray at work
 
G

Guillermo

This works for me:

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader ("Content-Disposition", "inline;
filename=somefile.xls");
}

Ray at work

Thank you very much, but this didn't solve my problem (I'm using
Office 2007, this could be the problem, I'll try Office 2003).

Your code works fine to change the file name from "page.aspx" to
"somefile.xls" in Internet Explorer 7 dialog box. But when I choose
"save", the default file name appears as "page.xls" instead of
"somefile.xls".

Also, when I choose "open", Excel 2007 receives a "page.aspx" file so
it still gives a warning. When I go on, the workbook is properly
displayed but title in Excel windows remains "page.aspx".

It's the same with DOC files, Word 2007 still shows "page.aspx" as
window title, but no warnings are displayed.

Thank you again.
 
G

Guillermo

This works for me:

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader ("Content-Disposition", "inline;
filename=somefile.xls");
}

Ray at work

My problem solved when using

Response.AddHeader ("Content-Disposition", "attachment;
filename=somefile.xls");

instead of

Response.AddHeader ("Content-Disposition", "inline;
filename=somefile.xls");

Thank you very much.
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top