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

Discussion in 'ASP .Net' started by guillermojco@gmail.com, Apr 24, 2007.

  1. Guest

    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.
     
    , Apr 24, 2007
    #1
    1. Advertising

  2. Ray Costanzo Guest

    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

    <> wrote in message
    news:...
    > 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.
    >
     
    Ray Costanzo, Apr 24, 2007
    #2
    1. Advertising

  3. Guillermo Guest

    On 24 abr, 19:30, "Ray Costanzo" <my first name at lane 34 dot
    commercial> wrote:
    > 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.
     
    Guillermo, Apr 26, 2007
    #3
  4. Guillermo Guest

    On 24 abr, 19:30, "Ray Costanzo" <my first name at lane 34 dot
    commercial> wrote:
    > 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.
     
    Guillermo, Apr 26, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    5
    Views:
    1,010
    Keith M. Corbett
    Sep 21, 2004
  2. Garg
    Replies:
    1
    Views:
    376
    Oliver Wong
    May 11, 2006
  3. Flip Rayner
    Replies:
    1
    Views:
    738
    bruce barker
    Jan 23, 2007
  4. lionel luo
    Replies:
    1
    Views:
    381
    Alexey Smirnov
    May 20, 2007
  5. David Morgan
    Replies:
    1
    Views:
    354
    raj chahal
    Feb 24, 2006
Loading...

Share This Page