PackagePart.CreateRelationship Method (Uri, TargetMode, String, String)
Assembly: WindowsBase (in WindowsBase.dll)
public PackageRelationship CreateRelationship( Uri targetUri, TargetMode targetMode, string relationshipType, string id )
- Type: System.Uri
The URI of the target part.
- Type: System.IO.Packaging.TargetMode
One of the enumeration values. For example, Internal if the target part is inside the Package; or External if the target is a resource outside the Package.
- Type: System.String
The role of the relationship.
- Type: System.String
A unique ID for the relationship.
The part has been deleted.
targetUri or relationshipType is null.
The targetMode parameter is not a valid TargetMode enumeration value.
The part identified by the targetUri is a relationship (the target of a relationship cannot be another relationship).
targetMode is specified as Internal but targetUri is an absolute external URI.
The package is read-only (a new relationship cannot be added).
id is not a valid XML identifier.
A part with the specified id already exists.
A part-level relationship defines an association between this part and a target part or resource. A part-level relationship can be one of two forms.
Between a source PackagePart to a target resource outside the package.
In a part-relationship the source part is considered the "owner" of the relationship. When the source part is deleted, all the relationships owned by the part are also deleted. The process of creating or deleting the relationship does not physically alter the target part or resource in any way.
id must be a valid XML identifier. The id type is xsd:ID and must follow the naming conventions prescribed in the XML Schema Part 2: Datatypes specification (see http://www.w3.org/TR/xmlschema-2/#ID).
The CreateRelationship method does not physically change either the source part, or the target part or resource in any way.
The target of a relationship cannot be another relationship.
If targetMode is specified as Internal, targetUri must be a relative URI that is formed in accordance with the RFC 3986 Uniform Resource Identifier (URI) Generic Syntax specification. The internal relative URI can be either an absolute path that starts with a forward slash ("/") character such as "/page1.xaml" or "/images/picture4.jpg", or a relative path such as "../imagespicture1.jpg" that resolves against the package root ("/") as the base URI.
If targetMode is specified as External, targetUri can be either an absolute or relative URI formed in accordance with the RFC 3986 Uniform Resource Identifier (URI) Generic Syntax specification. "http://www.microsoft.com/page2.xml" is an example of an absolute URI that references an external target resource "page2.xml". "images/picture1.jpg" is an example of a relative URI that also references an external target resource "1.jpg" but which resolves against the URI of the package itself.
relationshipType must be a URI that is formed according to the RFC 3986 Uniform Resource Identifier (URI) Generic Syntax specification. Different package types can define different part-level relationship types. The following table shows the part-level relationshipType URIs defined for documents that conform to the Open XML Paper Specification (XPS).
XPS Document Part-Level Relationship
Relationship Type URI
Digital Signature Definitions
For more information about package relationships see section 1.3 of the Open Packaging Conventions (OPC) specification available for download at http://go.microsoft.com/fwlink/?LinkID=71255.
For more information about XPS documents see the Open XML Paper Specification (XPS) available for download at http://go.microsoft.com/fwlink/?LinkID=67000.
Windows 7, Windows Vista SP1 or later, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later)