Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / March 2005

Tip: Looking for answers? Try searching our database.

Interop.word problem  "The RPC server is unavailable"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lee - 21 Mar 2005 14:23 GMT
Hi.
I'm new to c# .net programming, coming from a java background, and am
currently self learning the language trying to prepare a demo of a
windows.forms application of our current java client.
I've yet to undergo a training course, so im not sure if what i'm doing is
correct or not.
I'll post the code below, but what I'm trying to do is launch word documents
populating them with information which is returned to the windows form.
The Word.ApplicationClass object is expected to be available whilst the
client runs and can have many word documents attached.
Ive implemented this object as a static reference.

Ive added the word9.0 com object library reference to my project.
I can launch the word document fine, and have access to the interface and
able to modify the document. But, if I manually close the opened document.
Then re-execute the code to open another word doc, an
InteropServices.COMException is thrown.

with errors:
System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is
unavailable.
  at Word.ApplicationClass.get_Documents()

It seems any reference to Word.ApplicationClass.Documents throws this error
after Ive closed the first opened document.
Ive tried creating a new Word.ApplicationClass object (instead of using the
static object) each time to create a new document and the same problem
persists.
Ive had a google around and the only article i found which resembles this
problem was in MS Article ID : 188546.
It suggested creating a temp word application class first, then closing it,
then creating a new class to launch the document from.
This didnt work either, but I think that this article isnt the same problem
which I experience.

Id really like to know whether this can be done successfully as its a big
draw to our business that this type of letter functionality is possible with
our client gui.
Any help would be greatly appreciated.

below is the code i have used using the static reference:

in our main class:
public static Word.ApplicationClass s_wordApp = new Word.ApplicationClass();

method to retrieve word application:
public static Word.ApplicationClass getWordApp()
{
    return s_wordApp;
}

calling code to launch a word doc:

private void m_btnLetter_Click(object sender, System.EventArgs e)
{
    //  Set up all the parameters as generic objects so we can pass them in
Documents.Add

    object missing = System.Reflection.Missing.Value;
    object fileName = "normal.dot";   // template file name
    object newTemplate = false;  

    object docType = 0;
    object isVisible = true;
    object visibleFalse = false;

    //  Create a new Document, by calling the Add function in the Documents
collection
    Word.Document aDoc = null;
    try
    {
        aDoc = Form1.getWordApp().Documents.Add(ref fileName, ref newTemplate, ref
docType,
            ref    isVisible);

        //  need to see the created document, so make it visible

        Form1.getWordApp().Visible = true;
        aDoc.Activate();

        Form1.getWordApp().Selection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
        //  Toggle the title to a Bold Font
        Form1.getWordApp().Selection.Font.Bold = (int)Word.WdConstants.wdToggle;
        //  Type the Text of the Title that was inputted by the user in the Custom
Dialog

        string str = "text to be input to doc: " + m_txtSomeText.Text + ", more
text: " + m_txtSomeText1.Text;
        object start = 0;
        object end = 0;

        Word.Range rng = aDoc.Range(ref start, ref end);
        rng.Text = str;

    }
    catch (System.Runtime.InteropServices.COMException)
    {
    }

}
lee - 30 Mar 2005 09:33 GMT
anyone????

> Hi.
> I'm new to c# .net programming, coming from a java background, and am
[quoted text clipped - 97 lines]
>
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.