It works with the Office 2003 PIA tested on my computer with Office 2010:
using System.IO;
using System.Reflection;
using Microsoft.Office.Interop.Word;
public string GetHtmlFromDoc(string path)
var wordApp = new Application {Visible = false};
object srcPath = path;
var wordDoc = wordApp.Documents.Open(ref srcPath);
string destPath = Path.Combine(Path.GetTempPath(), "word" + (new Random().Next()) + ".html");
if (wordDoc != null)
{
object oDestPath = destPath;
object exportFormat = WdSaveFormat.wdFormatHTML;
wordDoc.SaveAs(ref oDestPath, ref exportFormat);
}
wordDoc.Close();
wordApp.Quit();
if (File.Exists(destPath))
{
return File.ReadAllText(destPath, Encoding.Default);
}
return null;
}
source
share