
StringBuilder sb=
new StringBuilder();

Microsoft.Office.Interop.Word.ApplicationClass appclass =
new Microsoft.Office.Interop.Word.ApplicationClass();
//实例化一个Word 
Type wordtype = appclass.GetType();

Microsoft.Office.Interop.Word.Documents docs = appclass.Documents;
//获取Document 
Type docstype = docs.GetType();
object filename =
@"C:\AA.doc";
//Word文件的路径 
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docstype.InvokeMember(
"Open", System.Reflection.BindingFlags.InvokeMethod,
null, docs,
new object[] { filename,
true,
true });
//打开文件 
Type doctype = doc.GetType();
object savefilename =
@"C:\bb.html";
//生成HTML的路径和名子 
doctype.InvokeMember(
"SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc,
new object[] { savefilename, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });
//另存为Html格式 
wordtype.InvokeMember(
"Quit", System.Reflection.BindingFlags.InvokeMethod,
null, appclass,
null);
//退出

Thread.Sleep(3000);
//为了使退出完全,这里阻塞3秒 
StreamReader objreader =
new StreamReader(savefilename.ToString(), System.Text.Encoding.GetEncoding(
"GB2312"));
//以下内容是为了在Html中加入对本身Word文件的下载 
FileStream fs =
new FileStream(savefilename.ToString().Split('.').GetValue(0).ToString() +
"$.html", FileMode.Create);

StreamWriter streamHtmlHelp =
new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding(
"GB2312"));
//streamHtmlHelp.WriteLine("<a href='E:\\AA.html'>源文件下载</a><br>");
string str = "";
do 
{

str = objreader.ReadLine();

sb.Append(str+
"\n");

sb.Replace(
"<Html>","");

sb.Replace(
"<body>", "");

streamHtmlHelp.WriteLine(str);

}
while (str !=
"</html>");

streamHtmlHelp.Close();

objreader.Close();

msg.InnerHtml = sb.ToString() ;

File.Delete(savefilename.ToString());

File.Move(savefilename.ToString().Split('.').GetValue(0).ToString() +
"$.html", savefilename.ToString());