Response.ContentType = "application/vnd.ms-excel" IGNORED!

Discussion in 'ASP .Net' started by Trapulo, Mar 17, 2010.

  1. Trapulo

    Trapulo Guest

    I've an application that worked well on IIS6. I moved it to IIS7, and
    response.contenttype is now ignored.

    my code ends with:

    Response.ContentType = "application/vnd.ms-excel"

    Response.Flush()
    Response.End()

    But the browser receives "application/octet-stream" as mime type! IE shows
    the XLS file as html/text, and FFOX propts to save.

    Why? :((

    thanks
    Trapulo, Mar 17, 2010
    #1
    1. Advertising

  2. Trapulo

    Mike Lovell Guest

    > I've an application that worked well on IIS6. I moved it to IIS7, and
    > response.contenttype is now ignored.
    >
    > my code ends with:
    >
    > Response.ContentType = "application/vnd.ms-excel"
    >
    > Response.Flush()
    > Response.End()
    >
    > But the browser receives "application/octet-stream" as mime type! IE shows
    > the XLS file as html/text, and FFOX propts to save.


    Could it be related to this bug report?

    https://connect.microsoft.com/Visua...lush-clears-content-type-header?wa=wsignin1.0

    I notice you're using Flush. They suggest that if you set the Content
    Length it won't happen.

    --
    Mike
    GoTinker, C# Blog
    http://www.gotinker.com
    Mike Lovell, Mar 18, 2010
    #2
    1. Advertising

  3. Trapulo

    Trapulo Guest

    Maybe can be, but it seems impossible that I may wait for .NET 4.0 to have
    this simple and old feature running.. :((



    "Mike Lovell" wrote:

    > > I've an application that worked well on IIS6. I moved it to IIS7, and
    > > response.contenttype is now ignored.
    > >
    > > my code ends with:
    > >
    > > Response.ContentType = "application/vnd.ms-excel"
    > >
    > > Response.Flush()
    > > Response.End()
    > >
    > > But the browser receives "application/octet-stream" as mime type! IE shows
    > > the XLS file as html/text, and FFOX propts to save.

    >
    > Could it be related to this bug report?
    >
    > https://connect.microsoft.com/Visua...lush-clears-content-type-header?wa=wsignin1.0
    >
    > I notice you're using Flush. They suggest that if you set the Content
    > Length it won't happen.
    >
    > --
    > Mike
    > GoTinker, C# Blog
    > http://www.gotinker.com
    >
    > .
    >
    Trapulo, Mar 24, 2010
    #3
  4. On Mar 24, 11:37 am, Trapulo <> wrote:
    > Maybe can be, but it seems impossible that I may wait for .NET 4.0 to  have
    > this simple and old feature running.. :((
    >
    >
    >
    > "Mike Lovell" wrote:
    > > > I've an application that worked well on IIS6. I moved it to IIS7, and
    > > > response.contenttype is now ignored.

    >
    > > > my code ends with:

    >
    > > >     Response.ContentType = "application/vnd.ms-excel"

    >
    > > >        Response.Flush()
    > > >        Response.End()

    >
    > > > But the browser receives "application/octet-stream" as mime type! IE shows
    > > > the XLS file as html/text, and FFOX propts to save.

    >
    > > Could it be related to this bug report?

    >
    > >https://connect.microsoft.com/VisualStudio/feedback/details/480689/re...

    >
    > > I notice you're using Flush.  They suggest that if you set the Content
    > > Length it won't happen.

    >
    > > --
    > > Mike
    > > GoTinker, C# Blog
    > >http://www.gotinker.com

    >
    > > .


    Do you have Response.Clear before that code? Maybe it helps
    Alexey Smirnov, Mar 24, 2010
    #4
  5. Trapulo

    Trapulo Guest

    "Alexey Smirnov" wrote:
    >
    > Do you have Response.Clear before that code? Maybe it helps


    I added now, but still the same :(
    I forgot to say that either .Flush and .End was added to try to solve this
    issue: on the IIS6 I didn't use them and all worked.

    thanks
    Trapulo, Mar 24, 2010
    #5
  6. Trapulo

    Trapulo Guest

    Where is MS "two business days" support?!


    "Trapulo" wrote:

    > I've an application that worked well on IIS6. I moved it to IIS7, and
    > response.contenttype is now ignored.
    >
    > my code ends with:
    >
    > Response.ContentType = "application/vnd.ms-excel"
    >
    > Response.Flush()
    > Response.End()
    >
    > But the browser receives "application/octet-stream" as mime type! IE shows
    > the XLS file as html/text, and FFOX propts to save.
    >
    > Why? :((
    >
    > thanks
    >
    Trapulo, Mar 30, 2010
    #6
  7. Hi Trapulo,

    Based on my understanding, you are facing the issue that IIS7 seems to
    ignore the ContentType property of a Response. However, based on my test,
    it works well with both ContentType property value of
    "application/vnd.ms-excel" and "application/octet-stream".

    As you didn't provide the complete code of this part in your page, it's
    hard to say where the problem is. So I would like to share the code of my
    test demo here. You may have a try with this code to see if this could help
    to solve the case.

    System.IO.FileInfo fi = new
    System.IO.FileInfo(Server.MapPath("TestExcel.xls"));
    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" +
    Server.UrlEncode(fi.Name));
    Response.AddHeader("Content-Length", fi.Length.ToString());
    Response.ContentType = "application/vnd.ms-excel";
    //Response.ContentType = "application/octet-stream";
    Response.WriteFile(fi.FullName);
    Response.End();

    Best Regards,
    Zhi-Qiang Ni
    Microsoft Online Support
    Zhi-Qiang Ni[MSFT], Mar 31, 2010
    #7
  8. Hi Trapulo,

    This is Zhi-Qiang Ni from MSDN Managed Newsgroup support team, since I
    haven't seen your reply after I last posted my reply, I'm writing to check
    the status of this post. Please feel free to let me know if there's
    anything else I can help. Thanks.


    Based on my understanding, you are facing the issue that IIS7 seems to
    ignore the ContentType property of a Response. However, based on my test,
    it works well with both ContentType property value of
    "application/vnd.ms-excel" and "application/octet-stream".

    As you didn't provide the complete code of this part in your page, it's
    hard to say where the problem is. So I would like to share the code of my
    test demo here. You may have a try with this code to see if this could help
    to solve the case.

    System.IO.FileInfo fi = new
    System.IO.FileInfo(Server.MapPath("TestExcel.xls"));
    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" +
    Server.UrlEncode(fi.Name));
    Response.AddHeader("Content-Length", fi.Length.ToString());
    Response.ContentType = "application/vnd.ms-excel";
    //Response.ContentType = "application/octet-stream";
    Response.WriteFile(fi.FullName);
    Response.End();

    --
    Regards,

    Zhi-Qiang Ni

    Microsoft Online Support
    Zhi-Qiang Ni[MSFT], Apr 7, 2010
    #8
  9. Trapulo

    M Minaga Guest

    M Minaga, Sep 15, 2010
    #9
    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. CVerma
    Replies:
    2
    Views:
    10,189
    C Verma
    Sep 28, 2004
  2. Replies:
    2
    Views:
    6,106
  3. Jerry O
    Replies:
    1
    Views:
    455
    Manohar Kamath [MVP]
    Sep 4, 2003
  4. Kevin Humphreys

    application/vnd.ms-excel

    Kevin Humphreys, Nov 26, 2004, in forum: ASP General
    Replies:
    1
    Views:
    206
    Tom B
    Nov 26, 2004
  5. Katie
    Replies:
    8
    Views:
    255
    Anthony Jones
    Aug 17, 2006
Loading...

Share This Page