6 Years
Discussion Span
Last Post by Mirfath

do you mean to open Microsoft word through C#?

yah exactly! Can you help me about this?


yah sure this is the code
first import these two headers and use them in your header section

using Microsoft.Office.Interop.Word;

using Microsoft.Office;

then write this code in a button click event:

Microsoft.Office.Interop.Word.Application wdApp = new Microsoft.Office.Interop.Word.Application();
            wdApp.Visible = true;
            Microsoft.Office.Interop.Word.Document aDoc = wdApp.Documents.Open(@"path where your word document exists");

hope this helps
let me knw if your having any problems

Edited by Mirfath: n/a


c# code use for connect microsoft word..

Thank you so much....


Check out this code...

///  <summary>

///This method read the document and writes into richtextbox control 

/// </summary>

         private void btn_Read_Click(object sender, EventArgs e)


            // call the method to read ms-word document



/// <summary>

        /// Read ms-word file

        /// </summary>

        public void ReadMsWord()

            // variable to store file path

            string filePath = null;

            // open dialog box to select file

            OpenFileDialog file = new OpenFileDialog();

            // dilog box title name

            file.Title = "Word File";

            // set initial directory of computer system

            file.InitialDirectory = "c:\\";

            // set restore directory

            file.RestoreDirectory = true;

            // execute if block when dialog result box click ok button

            if (file.ShowDialog() == DialogResult.OK)


                // store selected file path

                filePath = file.FileName.ToString();          




                // create word application

                Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.ApplicationClass();

                // create object of missing value

                object miss = System.Reflection.Missing.Value;

                // create object of selected file path

                object path = filePath;

                // set file path mode

                object readOnly = false;

                // open document                

                Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss,                                                                                    ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);

              // select whole data from active window document


                // handover the data to cllipboard


                // clipboard create reference of idataobject interface which transfer the data

                IDataObject data = Clipboard.GetDataObject();

                //set data into richtextbox control in text format

                richTextBox2.Text = data.GetData(DataFormats.Text).ToString();

                // read bitmap image from clipboard with help of iddataobject interface

                Image img = (Image)data.GetData(DataFormats.Bitmap);

                // close the document

                docs.Close(ref miss, ref miss, ref miss);


            catch (Exception ex) { MessageBox.Show(ex.ToString()); }


It might be resolve your problem.
For more details check [snipped]

Edited by Ezzaral: Added code tags and snipped promotional link.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.