显示word文件从SQL到网页
本文关键字:网页 SQL word 文件 显示 | 更新日期: 2023-09-27 18:03:35
我已经在二进制格式的SQL db中存储了.doc/.docx和pdf文件。我想在web浏览器中显示它们,我使用了以下代码。这里没有问题。pdf文件,它在网页上正确显示。但是对于。doc/。docx文件,网页上显示的数据是不格式化的。
DataSet ds = GetData(proID);
Byte[] bytes = (Byte[])ds.Tables[0].Rows[0]["Resume"];
Response.Buffer = true;
Response.Charset ="";
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (ds.Tables[0].Rows[0]["ContentType"].ToString() == ".doc" || ds.Tables[0].Rows[0]["ContentType"].ToString() == ".docx")
{
Response.ContentType = "application/vnd.ms-word";
}
else if (ds.Tables[0].Rows[0]["ContentType"].ToString() == ".pdf")
{
Response.ContentType = "application/pdf";
}
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
.doc/.docx的if条件不工作。无论如何,它将.doc/.docx文件的内容类型设置为"text/html"。有人能帮我做这件事吗?
下面应该可以。
HttpContext.Current.Response.ContentType = "application/vnd.ms-word";
或
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"