C# – Cannot open Office 2007 files from browser in ASP.NET application

asp.netcoffice-2007

I have an ASP.NET web page that opens a requested file and writes it into response so that file is supposed to open in browser. It works fine, but with Office 2007 file types (.xlsx, .docx, …) does not work properly. Basically, it returns nothing, an empty response, a blank response.

Actually, it only happens in my live servers (Windows Server 2008). In my test servers it works fine (and they are Windows Server 2008 too!).

The code looks like this:

string filePath = @"C:\mytests\test.docx";
string fileName = @"test";

Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = contentType;
Response.AddHeader(
   "content-disposition",
   "inline; filename=\"" + fileName + "\"");
Response.TransmitFile(filePath);

Best Answer

Investigate the MIME settings for Internet Explorer on the servers affected with this problem