如何在ASP.NET中读取.docx文件

时间:2015-03-13 05:03:11

标签: c# asp.net docx

当我读取.txt文件时,它会工作并显示,但当我读取.docx文件时,它会读取但以XML格式显示。如何将该XML格式转换为.docx?

代码是:

protected void viewfile(object sender, EventArgs e)
{
          string path = (sender as LinkButton).CommandArgument;
          if (!string.IsNullOrEmpty(path))
          {
                  string[] readText = File.ReadAllLines(path);
                  StringBuilder strbuild = new StringBuilder();
                  foreach (string s in readText)
                  {
                          strbuild.Append(s);
                          strbuild.AppendLine();
                  }
                          TextBox1.Text = strbuild.ToString();
          }
}

2 个答案:

答案 0 :(得分:0)

有一个库来操纵docx,请查看:http://docx.codeplex.com/

答案 1 :(得分:0)

引用此Using DocxToText to Extract Text from DOCX Files

您可以从.docx文件中提取文字,例如

DocxToText dtt = new DocxToText(docxFileName);
string text = dtt.ExtractText();