Previously, I used word to convert to HTMl. I found a similar piece of code on the Internet and found that a lot of code could not be executed. After debugging, I finally got it done for half a day.
The method is followed by the word file path. To execute such code, you need to add Microsoft. Office. Interop. Word. dll reference.
/// <Summary>
/// Convert Word to HTML
/// </Summary>
/// <Param name = "path"> </param>
Private string WordToHTMl (ref string path)
{
String pageUrl = null;
Object fltDocFormat = 10; // For filtered HTML Output
Object missing = System. Reflection. Missing. Value;
Object readOnly = false; // Open file in readOnly mode
Object isVisible = false; // The process has to be in invisible mode
Object fileName = path;
// Obtain the path of the website Server
String newPath = System. Web. HttpContext. Current. Server. MapPath ("/ConvertFiles /");
String newFileName = System. IO. Path. GetFileNameWithoutExtension (fileName. ToString ());
Object saveFileName = newPath + savePath + newFileName + ". html ";
// Determine whether the file is converted
If (! System. IO. File. Exists (SaveFileName ))
{
Microsoft. Office. Interop. Word. ApplicationClass objWord = new Microsoft. Office. Interop. Word. ApplicationClass ();
// Open the Word Document
ObjWord. documents. open (ref fileName, ref readOnly, ref missing, ref isVisible, ref missing, ref missing, ref missing );
// Do the background activity
ObjWord. Visible = false;
Microsoft. Office. Interop. Word. Document oDoc = objWord. ActiveDocument;
ODoc. saveAs (ref saveFileName, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing );
ODoc. Close (ref missing, ref missing, ref missing );
ObjWord. Quit (ref missing, ref missing, ref missing );
// Process [] myProcesses = Process. GetProcessesByName ("WINWORD ");
// Foreach (Process myProcess in myProcesses)
//{
// MyProcess. Kill ();
//}
// String pageUrl = newFileName + ". html ";
// System. Web. HttpContext. Current. Server. Transfer (pageUrl );
}
Else
{
// Page path
PageUrl = IpPath + FileName + ". html ";
}
Return pageUrl;
}