Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi to evry one.
Firs i am sorry for my bad english language.
i work on winform application that load word file in web browser control with convert word to html that work fine
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Microsoft.Office.Interop.Word;
using System.IO;
namespace myapp
{

    delegate void ConvertDocumentDelegate(string fileName);
    public partial class DrugInfoForm : Telerik.WinControls.UI.RadForm
    {
        object oDocument;
        public MyAppForm(string _docname)
        {
            InitializeComponent();
            doc_name = _docname;
        }
        string doc_name;
          string tempFileName = null;
        private void MyAppForm_Load(object sender, EventArgs e)
        {
            string filen= "word path";

            LoadDocument(filen);
           
        }
         public void LoadDocument(string fileName)
    {
        // Call ConvertDocument asynchronously. 
        ConvertDocumentDelegate del = new ConvertDocumentDelegate(ConvertDocument);

        // Call DocumentConversionComplete when the method has completed. 
        del.BeginInvoke(fileName, DocumentConversionComplete, null);
    }
           void ConvertDocument(string fileName)
                 {
                    object m = System.Reflection.Missing.Value;
                    object oldFileName = (object)fileName;
                    object readOnly = (object)false;
                    Microsoft.Office.Interop.Word.ApplicationClass  ac = null;

        try
        {
            // First, create a new Microsoft.Office.Interop.Word.ApplicationClass.
            ac = new Microsoft.Office.Interop.Word.ApplicationClass();

            // Now we open the document.
            Document doc = ac.Documents.Open(ref oldFileName, ref m, ref readOnly,
                ref m, ref m, ref m, ref m, ref m, ref m, ref m,
                 ref m, ref m, ref m, ref m, ref m, ref m);

            // Create a temp file to save the HTML file to. 
            tempFileName = GetTempFile("html");

            // Cast these items to object.  The methods we're calling 
            // only take object types in their method parameters. 
            object newFileName = (object)tempFileName;

            // We will be saving this file as HTML format. 
            object fileType = (object)WdSaveFormat.wdFormatHTML;

            // Save the file. 
            doc.SaveAs(ref newFileName, ref fileType,
                ref m, ref m, ref m, ref m, ref m, ref m, ref m,
                ref m, ref m, ref m, ref m, ref m, ref m, ref m);

        }
        finally
        {
            // Make sure we close the application class. 
            if (ac != null)
                ac.Quit(ref readOnly, ref m, ref m);
        }
    }
        void DocumentConversionComplete(IAsyncResult result)
    {
        // navigate to our temp file. 
        webBrowser1.Navigate(tempFileName);
    }
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

            if (tempFileName != string.Empty)
            {
                // delete the temp file we created. 
               System.IO.File.Delete(tempFileName);

                // set the tempFileName to an empty string. 
                tempFileName = string.Empty;
            }
        }
        string GetTempFile(string extension)
        {
            // Uses the Combine, GetTempPath, ChangeExtension, 
            // and GetRandomFile methods of Path to 
            // create a temp file of the extension we're looking for. 
            return Path.Combine(Path.GetTempPath(),
              Path.ChangeExtension(Path.GetRandomFileName(), extension));
        }

       
    }
}


BUT
i have problem with link in word file , i want to word file that linked open like before
but when click in links open microsoft word in web browser i dont want this
please help me
Posted
Comments
Maciej Los 23-Jul-14 11:16am    
What do you want to do? Do you want to convert links to <a href="link">description</a>?
saeed jahandar 23-Jul-14 12:31pm    
so so ,i want convert "href" to file location path


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900