Recently in the Word document online Browsing, find a variety of methods, controls, return to Word to HTML, online browsing ....
Is the background code, the foreground HTML page default code can be.
Because the file is as follows:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using system.web.ui.webcontrols;using system.io;using Word = Microsoft.Office.Interop.Word;
Using Word = Microsoft.Office.Interop.Word;
Without referencing a good component, there will be an error here, no interop, etc.
In this case, you need to refer to the Microsoft.office.interop.visio,microsoft.office.interop.word in the reference component. Net
The background code is as follows:
protected void Page_Load (object sender, EventArgs e) {string relativepath = request.querystring["File Path "]; Relative path, from the jump page to get the file relative path. if (RelativePath = = "" | | Relativepath==null) return; String serverpath = Server.MapPath (RelativePath); Relative to the server corresponding to the path string html = Serverpath.replace (". Doc", ". html"); if (! File.exists (@html))//html page does not exist, convert Word to HTML {string filename = wordtohtml (Serverpath); StreamReader fread = new StreamReader (filename, System.Text.Encoding.GetEncoding ("gb2312")); string ss = Fread. ReadToEnd (); Response.Write (ss); Writing a string directly to the Web page will reveal that the text can be displayed, and the picture or table cannot be displayed. So back to the HTML file page. Fread. Close (); Fread. Dispose (); } HTML = Relativepath.replace (". Doc", ". html"); The HTML file is also stored in the same path,//only need to change the original path suffix to get the HTML file path Response.Redirect (HTML); Return }///<summary>//Word to HTML//</summary>//<param name= "Wordfilename "></param> private string Wordtohtml (object wordfilename) {//Place user code here to initialize page Word.Application word = new Word.Application (); Type Wordtype = Word. GetType (); word.documents docs = Word. Documents; Open 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 format, save as 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); Quit Word wordtype.invokemember ("Quit", System.Reflection.BindingFlags.InvokeMethod, NULL, Word, NULL); return savefilename.tostring (); }
ASP. NET implements online browsing of Word documents (Word to HTML)