From: Trapulo on
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
>
From: Zhi-Qiang Ni[MSFT] on
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

From: Zhi-Qiang Ni[MSFT] on
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

First  |  Prev  | 
Pages: 1 2
Prev: Unit Testing ASP.NET
Next: LinqToEntitiesDomainService