Open word on the page and browse online

Source: Internet
Author: User

 

 

/// <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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.