Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have an app developed n C#, i am able to open the Word file from the list box but if i close and reopen the same document again i am getting the error
RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
the code i am using is below
private Word.ApplicationClass WordApp = new Word.ApplicationClass();

public void OpenDocument(object DocName)
       {
           try
           {

               WordApp.Visible = true;
               object optional = System.Type.Missing;
               object missing = System.Reflection.Missing.Value;
               object isVisible = true;
               Word.Document aDoc = WordApp.Documents.Open(ref DocName, ref       optional, ref optional,
                   ref optional, ref optional, ref optional, ref optional, ref optional, ref optional,
                   ref optional, ref optional, ref optional);
               aDoc.Activate();
           }

           catch (Exception e)
           {
               MessageBox.Show(e.Message);
           }
       }
private void listBox1_DoubleClick(object sender, EventArgs e)
       {
           try
           {
               string DocName;
               DocName = txtPath.Text.ToString();
               OpenDocument(DocName);
           }
           catch (Exception er1)
           {
               MessageBox.Show("" + er1.Message);
           }
       }
Posted

If you closed word yourself, then the connection to the word object that your application created is lost. It is simply not the same reference when you reopen the word document. The application should create a new word application and reopen the document itself.

Also, be aware that when the word document that you created with your application is visible, some strange errors can occur when a user interacts with that word instance. You then lose control over it programmability. Simply keep it hidden until you are done and check the reference before using it again.

Good luck!
 
Share this answer
 
The word application objects have events ApplicationEvents2_Event_Quit & ApplicationEvents2_Event_DocumentBeforeClose events what I have done before is set a flag for myself


I have used this solution on Word 2003

Cheers
 
Share this answer
 

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