I’m experimenting with the System.IO.Packaging namespace to store some custom files and then read them out later back into code.
I’m having difficulty finding a definitive example on how to use/set the ID property of a PackagePartRelationship.
For example if I have the following:
var relationship = packagePart.CreateRelationship(documentPart.Uri, TargetMode.Internal, relationshipType, relationshipId);
What format should the parameter ‘relationshipId’ have? All that is stated in the MSDN documentation is that it should adhere to the rules for a valid xsd:Id value from the XML scheme datatype definitions. But searching through that, I can’t find a set answer either.
Also, in case anyone asks, the reason I want to specify the Id rather than letting it be auto generated is because the will be some relationship chains in the package that only have on “child” or “relationship” associated with it. So rather than looping over
packagePart.GetRelationships()
Or
packagePart.GetRelationshipByType(relationshipType)
I want to be able to do
packagePart.GetRelationship(relationshipId)
Many thanks.
xsd:id is an xsd:NCName with a unique constraint.
So no colons, no commas and can’t start with a number.