在网页上打开word文件内容
本文关键字:文件 word 网页 | 更新日期: 2023-09-27 18:17:41
我的details文件夹中有word文件,我想在浏览器中显示该word文件。它告诉我不是有效的虚拟路径错误
string filename = "http://something.in/management/details/" + DS.Tables["Table"].Rows[0]["DETAILS"].ToString();
if (filename != "")
{
string path = Server.MapPath(filename);
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/ms-word";
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write("This file does not exist.");
}
}
Server.MapPath(filename)将不接受URL
用法参见this和this
。
string filename =
Server.MapPath("~/management/details/" + DS.Tables["Table"].Rows[0]["DETAILS"].ToString());
也可以在这里使用其他类型的uning Server.MapPath