【发布时间】:2015-04-24 17:50:57
【问题描述】:
我有以下代码来显示 word 文档,我将结果显示到文本区域,但不知道如何在 mvc 的引导模式中实现它。我正在关注提到的链接,任何人都可以帮助我实现这一目标。
这是我的控制器代码。
public JsonResult ReadTextFile(string fName)
{
string retString = string.Empty;
string path = Path.Combine(Server.MapPath("~/Media"), fName);
if (System.IO.File.Exists(path))
{
if (Path.GetExtension(path) == "doc" || Path.GetExtension(path) == ".docx")
{
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object miss = System.Reflection.Missing.Value;
object readOnly = true;
object wordPath = path;
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(
ref wordPath,
ref miss,
ref readOnly,
ref miss, ref miss, ref miss,
ref miss, ref miss, ref miss,
ref miss, ref miss, ref miss,
ref miss, ref miss, ref miss, ref miss);
for (int i = 0; i < docs.Paragraphs.Count; i++)
{
retString += " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
}
}
else if (Path.GetExtension(path) == "txt")
{
using (StreamReader sr = new StreamReader(path))
{
retString = sr.ReadToEnd();
}
}
}
return Json(retString, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
标签: json asp.net-mvc-4