none
word add-in system.io.packaging 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 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

    const string relationshipNamespace = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";

    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="http://schemas.openxmlformats.org/package/2006/relationships">
       <Relationship Id="context" Target="docProps/context.xml" Type="http://www.fit.fraunhofer.de/xml/context1.0" />
      </Relationships>
     
    my .xml file content is
     
    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    - <cx:context xmlns:cx="http://www.fit.fhg.de/context/spec1.1/" cx: docid="860a4b2e-81c0-4320-970a-f927bc053c0b">
      <cx: scope cx:initdata="1192198631222" cx:lastvisit="1192198631222" cx:url="http://saafi.fit.fhg.de/contextbroker/" />
      </cx:context>
     
    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