2012-04-12 51 views
0

我想在瀏覽器中打開二進制Word文檔文件,而不是從物理路徑打開。使用下面給出的代碼,我可以在瀏覽器中打開PDF文件,但不能打開其他文件。如何在瀏覽器中打開Word文檔?

CODE:

byte[] obFile = null; 
obFile = (byte[])fds.Tables[0].Rows[0]["File"]; 
String aFileName = "abc"; 
Response.Expires = 0; 
Response.ClearContent(); 
Response.Buffer = true; 
Response.BufferOutput = true; 
Response.ContentType = "application/msword;name=abc.docx"; 
Response.AddHeader("content-transfer-encoding", "binary"); 
Response.AddHeader("content-length", obFile.Length.ToString()); 
Response.AddHeader("Content-Disposition", "inline; filename=abc.docx"; 
Response.CacheControl = "public"; 
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1251); 
Response.OutputStream.Write(obFile, 0, obFile.Length); 
Response.End(); 
+0

緩衝區必須關閉,如果你從aspx頁面調用它,那麼它可能會使它成爲gzip並且無法加載它。需要使一個處理程序(一個.ashx文件)發送它。你得到什麼錯誤?我認爲這裏有一個bug是obfile。這是正確的嗎? – Aristos 2012-04-12 17:08:43

回答

0

您可以使用Flash/Silverlight庫來顯示文檔。微軟也有Office Web Apps(需要許可證),可以在瀏覽器上顯示和編輯office文檔