0

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);
German Latorre
  • 10,058
  • 14
  • 48
  • 59

4 Answers4

1

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

Andrew Keith
  • 7,515
  • 1
  • 25
  • 41
0

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

Alex H
  • 733
  • 4
  • 8
0

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
  • 12,355
  • 5
  • 41
  • 45
  • 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 Oct 13 '09 at 10:02
  • Actually, contentType variable contains exactly that string for the files I'm using for testing. Page is an .ashx address. – German Latorre Oct 13 '09 at 11:04
0

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

Ruffles
  • 79
  • 1
  • 3