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

  • Thread starter Thread starter Trapulo
  • Start date Start date
T

Trapulo

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
 
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.
 
Maybe can be, but it seems impossible that I may wait for .NET 4.0 to have
this simple and old feature running.. :((
 
Maybe can be, but it seems impossible that I may wait for .NET 4.0 to  have
this simple and old feature running.. :((

Do you have Response.Clear before that code? Maybe it helps
 
Alexey Smirnov said:
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
 
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
 
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
 
Back
Top