【发布时间】:2016-12-28 19:45:33
【问题描述】:
我已将 .doc/.docx 和 pdf 文件以二进制格式存储在 SQL db 中。我想在网络浏览器中显示它们,我使用了以下代码。 .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”。谁能帮我做这件事?
【问题讨论】:
-
您是否只是尝试了明显的“应用程序/ms-word”
-
是的。我尝试使用“application/ms-word”。但它会下载 .aspx 页面
-
我用“Response.ContentType = “application/vnd.openxmlformats-officedocument.wordprocessingml.document”;”试过了。但它会从我想在浏览器/网页中显示的数据库中下载 word 文件