首先要 添加引用,来自于.net 3.0的windowsBase
引入namespace
using System.IO;
using System.IO.Packaging;
using System.Xml;
//源文件
string fileName = @"d:\test.docx";
//文档序列化存储类,相当于一个zip
using (Package package = Package.Open(fileName, FileMode.Open, FileAccess.Read))
{
//文档的内部结构
Uri docxUri = new Uri("/word/document.xml", UriKind.Relative);
PackagePart docxPart = package.GetPart(docxUri);
XmlDocument docxXmlDocument = new XmlDocument();
//读入到xml
docxXmlDocument.Load(docxPart.GetStream());
MessageBox.Show(docxXmlDocument.InnerText, "message");
//分析xml
package.Close();
}