1.页面
<div class="cont">
<span class="label">操作手册</span>
@Html.ActionLink(查看, "ViewManual", "Home", new { target = "_blank", @class = "btn main_btn" })
<a href="/home/path" class="btn">下载</a>
</div>
2.HomeController
引用dll
public ActionResult ViewManual()
{
try
{
string virtualURL = ConfigurationManager.AppSettings["ManualPath"].ToString();
string physicalPath = Server.MapPath(Server.UrlDecode(virtualURL));
if (string.IsNullOrEmpty(virtualURL) || !System.IO.File.Exists(physicalPath))
{
return Json("请先上传系统手册至站点目录下,并在配置文件(appSettings.config)中配置路径信息!", JsonRequestBehavior.AllowGet);
}
string extension = Path.GetExtension(physicalPath);
string htmlUrl = "";
switch (extension.ToLower())
{
case ".doc":
case ".docx":
htmlUrl = PreviewWord(physicalPath, virtualURL);
break;
}
return Redirect(Url.Content(htmlUrl));
}
catch (Exception ex)
{
return Json(ex.Message, JsonRequestBehavior.AllowGet);
}
}
========================
public static string PreviewWord(string physicalPath, string virtualURL)
{
string htmlName = Path.GetFileNameWithoutExtension(physicalPath) + ".html";
if (File.Exists(Path.GetDirectoryName(virtualURL)+"/"+htmlName))
File.Delete(Path.GetDirectoryName(virtualURL) + "/" + htmlName);
Aspose.Words.Document d = new Aspose.Words.Document(physicalPath);
d.Save(Path.GetDirectoryName(physicalPath) + "\\" + htmlName, SaveFormat.Html);
return Path.GetDirectoryName(virtualURL) + "\\" + htmlName; ;
}