Using the methods provided by word. Application, you can easily convert Word documents into other formats such as HTML.Code:
Visual C #
Wordtohtml. aspx
<% @ Page Language = "C #" codebehind = "wordtohtml. aspx. cs" autoeventwireup = "false"
Inherits = "aspxwebcs. wordtohtml" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> wordtohtml </title>
<Meta name = "generator" content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "code_language" content = "C #">
<Meta name = "vs_defaultclientscript" content = "JavaScript">
<Meta name = "vs_targetschema" content = "http://schemas.microsoft.com/intellisense/ie5">
</Head>
<Body ms_positioning = "gridlayout">
<Form ID = "form1" method = "Post" runat = "server">
</Form>
</Body>
</Html>
Wordtohtml. aspx. CS
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using office;
Namespace aspxwebcs
{
/// <Summary>
/// Summary of wordtohtml.
/// Add reference: Microsoft Word 9.0 Object Library
/// </Summary>
Public class wordtohtml: system. Web. UI. Page
{
Private void page_load (Object sender, system. eventargs E)
{
// 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 ();
Object filename = "d :\\ TMP \ aaa.doc ";
Word. Document Doc = (word. Document) docstype. invokemember ("open ",
System. reflection. bindingflags. invokemethod, null, Docs, new object [] {filename, true, true });
// Convert the format and save it
Type doctype = Doc. GetType ();
Object savefilename = "D: \ TMP \ aaa.html ";
// The following is the Microsoft Word 9 Object Library statement. If it is 10, it may be written as follows:
// Doctype. invokemember ("saveas", system. reflection. bindingflags. invokemethod,
Null, Doc, new object [] {savefilename, word. wdsaveformat. wdformatfilteredhtml });
/// Other formats:
/// Wdformathtml
/// Wdformatdocument
/// Wdformatdostext
/// Wdformatdostextlinebreaks
/// Wdformatencodedtext
/// Wdformatrtf
/// Wdformattemplate
/// Wdformattext
/// Wdformattextlinebreaks
/// Wdformatunicodetext
Doctype. invokemember ("saveas", system. reflection. bindingflags. invokemethod,
Null, Doc, new object [] {savefilename, word. wdsaveformat. wdformathtml });
// Exit word
Wordtype. invokemember ("quit", system. reflection. bindingflags. invokemethod,
Null, word, null );
}
# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}