Therefore, an HTML file is saved when each file is uploaded, so that the online preview function can be realized. Main Code As follows:
Copy code The Code is as follows: using system;
Using system. collections;
Using system. configuration;
Using system. Data;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using word = Microsoft. Office. InterOP. word;
Public partial class test: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Wordtohtml ("D: \ yijian.doc ");
}
/// <Summary>
/// Convert Word to HTML
/// </Summary>
/// <Param name = "wordfilename"> </param>
Private string wordtohtml (Object wordfilename)
{
// Place user code here to initialize the page
Word. applicationclass word = new word. applicationclass ();
Type wordtype = word. GetType ();
Word. Documents docs = word. documents;
// Open the file
Type docstype = docs. GetType ();
Word. document Doc = (word. document) docstype. invokemember ("open", system. reflection. bindingflags. invokemethod, null, Docs, new object [] {wordfilename, true, true });
// Convert the format and save it
Type doctype = Doc. GetType ();
String wordsavefilename = wordfilename. tostring ();
String strsavefilename = wordsavefilename. substring (0, wordsavefilename. Length-3) + "html ";
Object savefilename = (object) strsavefilename;
Doctype. invokemember ("saveas", system. reflection. bindingflags. invokemethod, null, Doc, new object [] {savefilename, word. wdsaveformat. wdformatfilteredhtml });
Doctype. invokemember ("close", system. reflection. bindingflags. invokemethod, null, Doc, null );
// Exit word
Wordtype. invokemember ("quit", system. reflection. bindingflags. invokemethod, null, word, null );
Return savefilename. tostring ();
}
}
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.