我想在浏览器中打开二进制 Word 文档文件,而不是从物理路径。使用下面给出的代码,我可以在浏览器中打开 PDF 文件,但不能打开其他文件。
代码:
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();