word add-in RRS feed

  • Question


    hello everyone,


                           I have installed the openxmlsdk and added reference to my word add-in project but i couldnt get the package class in my project. i need to implement this



    using (Package package = Package.Open("mydocument.docx"))






    string relID= rId1;

    PackageRelationship imagerelationship = mainPart.GetRelationship(relID);


    in my project


    namespace wordplugin


    public partial class ThisAddIn


    const string wordmlNamespace = "";

    const string relationshipNamespace = "";

    private void ThisAddIn_Startup(object sender, System.EventArgs e)


    this.Application.DocumentOpen += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);


    void Application_DocumentOpen(Microsoft.Office.Interop.Word.Document Doc)


           // implement the package class to retrieve the a .xml file using the relationship id "context" and retreive the

          cx : docid and cx : scope in a message box here. so that the a file is opened using the word it checks for the context.xml file with the realtionship id and display the content in message box.



    my relationship id is


    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>

    - <Relationships xmlns="">
       <Relationship Id="context" Target="docProps/context.xml" Type="" />
    my .xml file content is
    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    - <cx:context xmlns:cx="" cx: docid="860a4b2e-81c0-4320-970a-f927bc053c0b">
      <cx: scope cx:initdata="1192198631222" cx:lastvisit="1192198631222" cx:url="" />
    Thank you.

    Thursday, March 20, 2008 5:31 PM

All replies


    If you are getting an exception, it is likely because Word has the file locked for reading.  Since System.IO.Packaging would be invoked after Word has already loaded the file, it would not be possible for your Add-In to take an additional lock on the file. 


    Could you give some more data about what the task is you're looking to accomplish? It appears you're trying to get your own XML data island out of the document by using the OPC format.  Is that a correct assumption?



    Thursday, March 20, 2008 11:11 PM

    hi art leonard,


    Yeah you are right. iam embedding my own .xml file with the .docx. so i need to create a add-in that check each document when it is opened with word whether my .xml file is there. if is there then i need retreive some node data and display it. for example as i specified before cx: docid from the .xml file.


    or is there some other way to read the .xml file from the document other than this packaging class?..


    Thank you.

    Friday, March 21, 2008 8:03 AM