views:

454

answers:

4

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);
+1  A: 

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

Andrew Keith
A: 

Try adding Response.End() at the end to close.

Aliixx
A: 

On the live server, check the MIME Types in the Internet Information Services (IIS) Manager.

I think:

.docx should be application/vnd.openxmlformats-officedocument.wordprocessingml.document .xlsx should be application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

JDunkerley
I've checked that and seems to be OK, still doesn't work...
antur123
Try replacing the line `Response.ContentType = contentType;` with `Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";` (for a .docx file). I wonder if this is the issue, as I guess the page is a .aspx address?
JDunkerley
Actually, contentType variable contains exactly that string for the files I'm using for testing. Page is an .ashx address.
antur123
A: 

Is it possible your live servers are in a different security zone to your test servers? e.g. Intranet vs. Internet?

Ruffles