private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"D:\Sample.doc"); //Save doc file. document.SaveToFile("Sample.html", FileFormat.Html); //Launching the MS Word file. WordDocViewer("Sample.html"); } private void WordDocViewer(string fileName) { try { System.Diagnostics.Process.Start(fileName); } catch { } }
Never give up! Smile to the world! http://excelcsharp.blog.com/
<table width="100%"> <tr> <td> Select WORD file to display:<br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <asp:Button ID="Button1" runat="server" Text="Convert" onclick="Button1_Click" /> </td> </tr> <tr> <td> <div id="report_container" runat="server"></div> </td> </tr> </table>
using Docs.Word; using System.IO; protected void Button1_Click(object sender, EventArgs e) { Document doc = null; string name = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName); string ext = Path.GetExtension(FileUpload1.PostedFile.FileName); try { switch (ext.ToLower()) { case ".docx": doc = Document.ReadDOCX(FileUpload1.PostedFile.InputStream); break; case ".doc": doc = Document.ReadDOC(FileUpload1.PostedFile.InputStream); break; case ".rtf": doc = Document.ReadRTF(FileUpload1.PostedFile.InputStream); break; case ".txt": doc = Document.ReadTXT(FileUpload1.PostedFile.InputStream); break; default: report_container.InnerHtml = "Please select docx, doc or rtf file"; return; } } catch (Exception ex) { report_container.InnerHtml = ex.Message; return; } report_container.InnerHtml = doc.WriteHTML(System.Text.Encoding.ASCII); }
@$H!$H K@N$@L
Login to post response