/// <Summary>
/// Put it in a class file for general purpose, and other objects are not directly called
/// </Summary>
/// <Param name = "FILENAME"> obtain the name and suffix of the uploaded file. </param>
/// <Param name = "infilepath"> path of the file to be opened </param>
/// <Param name = "showpath"> generate static page paths and some other files </param>
/// <Param name = "outdirpath"> it can be empty. </param>
/// <Returns> </returns>
Public static tuple <string, string> priview (string filename, string infilepath, string outdirpath = "")
{
Object missingtype = type. missing;
Object readonly = true;
Object isvisible = false;
Object documentformat = 8;
// String randomname = datetime. Now. tostring ("yyyymmddhhmmss ");
String randomname = filename. Remove (filename. lastindexof ("."));
Object htmlfilepath = outdirpath + randomname + ". html ";
String directorypath = outdirpath + randomname + "_ FILES ";
Object filepath = infilepath;
// Open the Word document in background
Applicationclass = new applicationclass ();
Applicationclass. Documents. Open (ref filepath,
Ref readonly,
Ref missingtype, ref missingtype, ref missingtype,
Ref missingtype, ref missingtype, ref missingtype,
Ref missingtype, ref missingtype, ref isvisible,
Ref missingtype, ref missingtype, ref missingtype,
Ref missingtype, ref missingtype );
Applicationclass. Visible = false;
Document document = applicationclass. activedocument;
// Save the Word document as HTML file
Document. saveas (ref htmlfilepath, ref documentformat, ref missingtype,
Ref missingtype, ref missingtype, ref missingtype,
Ref missingtype, ref missingtype, ref missingtype,
Ref missingtype, ref missingtype, ref missingtype,
Ref missingtype, ref missingtype, ref missingtype,
Ref missingtype );
// Close the Word Document
Document. Close (ref missingtype, ref missingtype, ref missingtype );
Killpreviewwordprocess ();
Return new tuple <string, string> (randomname, htmlfilepath. tostring ());
}
/// <Summary>
/// Close all the word background processes used for previewing
/// </Summary>
Public static void killpreviewwordprocess ()
{
// Process. getprocessesbyname ("winword "). tolist (). where (PRO => string. isnullorwhitespace (Pro. mainwindowtitle )). tolist (). foreach (nullpro => nullpro. kill ());
Process [] wordprocess = process. getprocessesbyname ("winword ");
Try
{
Foreach (process pro in wordprocess)
{
String MWt = pro. mainwindowtitle;
If (string. isnullorwhitespace (MWT ))
{
Pro. Kill ();
}
}
}
Catch
{
}
}
Use on the page
Tuple <string, string> tuplew = wordpreview. priview (this, get_name, filepath, outputdirpath );
Dname = tuplew. item1.tostring ();
Jsputility. openWindow (". /html/"+ filenamewithnoext. tostring () + ". html "," "," 1366 "," 768 ", updatepanel1); // generate the path of the static page. Note: