wordpress hit counter
Retrieving the correct CustomXML part (using System.IO.Packaging) - .Net - Development Tools - OpenXML Developer

Retrieving the correct CustomXML part (using System.IO.Packaging)

Development Tools

Discussions about working with Open XML using a wide range of development tools

Retrieving the correct CustomXML part (using System.IO.Packaging)

  • rated by 0 users
  • This post has 1 Reply |
  • 2 Followers
  •  

    Hello,

     

    I'm trying to figure out how I can select a specific CustomXML part from an openxml document (without using Word).

     

    The custom xml is added to the document using a word add-in. I've used a namespace in the xml, so within the addin, I can easily retrieve the custom part again:

     

    CustomXMLParts xmlParts =

    doc.CustomXMLParts.SelectByNamespace("urn:some-unique-namespace");

     

     
    Now, I need to retrieve the correct CustomXML part again when the file is uploaded to a serve (so without using Word).
     
    I can retrieve all the custom XML parts using the Relationships of the main document, but how do know I have the correct one without loading the part & examining the XML

     

         PackagePart docPart =

    GetDocumentXmlPart(package); //this returns the main document part

    foreach (PackageRelationship docRel in docPart.GetRelationshipsByType(

    @http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml))

    {

    //how do I know it's the correct one?

    return package.GetPart(PackUriHelper.ResolvePartUri(

        new Uri("/", UriKind.Relative), docRel.TargetUri));

    }

    return null;

     

     

    Any ideas?

    Sven De Bont - MCAD - http://www.sdbonline.com/blog
  • I am having the same problem.
    I add customXml part from code (using Package), then open it in Word. Manualy changeing content and save it. Now Word automaticaly changed customXmlPart name ( from "/customXml/myPart1.xml" to "/customXml/item1.xml") and retationship id (from "myPartID1" to "rId1").
    I am wondering if examinig xml is the only solution?
Page 1 of 1 (2 items)