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

mvc-在线弹出新页面查看word文档

  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; ;

        }

相关文章:

  • 2021-12-05
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2021-12-09
  • 2021-12-09
  • 2021-06-15
  • 2021-04-12
  • 2021-08-27
  • 2021-12-19
  • 2022-12-23
相关资源
相似解决方案