Export (0) Print
Expand All

PackagePart.CreateRelationship Method (Uri, TargetMode, String, String)

Creates a part-level relationship between this PackagePart to a specified target PackagePart or external resource.

Namespace:  System.IO.Packaging
Assembly:  WindowsBase (in WindowsBase.dll)

public PackageRelationship CreateRelationship(
	Uri targetUri,
	TargetMode targetMode,
	string relationshipType,
	string id
)

Parameters

targetUri
Type: System.Uri

The URI of the target part.

targetMode
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.

relationshipType
Type: System.String

The role of the relationship.

id
Type: System.String

A unique ID for the relationship.

Return Value

Type: System.IO.Packaging.PackageRelationship
The part-level relationship between this PackagePart to the target PackagePart or external resource.

ExceptionCondition
InvalidOperationException

The part has been deleted.

-or-

The Package is not open (Dispose or Close has been called).

ArgumentNullException

targetUri or relationshipType is null.

ArgumentOutOfRangeException

The targetMode parameter is not a valid TargetMode enumeration value.

ArgumentException

The part identified by the targetUri is a relationship (the target of a relationship cannot be another relationship).

-or-

targetMode is specified as Internal but targetUri is an absolute external URI.

IOException

The package is read-only (a new relationship cannot be added).

XmlException

id is not a valid XML identifier.

-or-

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.

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

http://schemas.microsoft.com/xps/2005/06/signature-definitions

DiscardControl

http://schemas.microsoft.com/xps/2005/06/discard-control

DocumentStructure

http://schemas.microsoft.com/xps/2005/06/documentstructure

PrintTicket

http://schemas.microsoft.com/xps/2005/06/printticket

Required Resource

http://schemas.microsoft.com/xps/2005/06/required-resource

Restricted Font

http://schemas.microsoft.com/xps/2005/06/restricted-font

StartPart

http://schemas.microsoft.com/xps/2005/06/fixedrepresentation

StoryFragments

http://schemas.microsoft.com/xps/2005/06/storyfragments

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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft