我想在浏览器中打开二进制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();
缓冲区必须关闭,如果你从aspx页面调用它,那么它可能会使它成为gzip并且无法加载它。需要使一个处理程序(一个.ashx文件)发送它。你得到什么错误?我认为这里有一个bug是obfile。这是正确的吗? – Aristos 2012-04-12 17:08:43