Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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
)
public PackageRelationship CreateRelationship (
	Uri targetUri, 
	TargetMode targetMode, 
	String relationshipType, 
	String id
)
public function CreateRelationship (
	targetUri : Uri, 
	targetMode : TargetMode, 
	relationshipType : String, 
	id : String
) : PackageRelationship
You cannot use methods in XAML.

Parameters

targetUri

The of the target part.

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

The role of the relationship.

id

A unique ID for the relationship.

Return Value

The part-level relationship between this PackagePart to the target PackagePart or external resource.
Exception typeCondition

InvalidOperationException

The part has been deleted.

-or-

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

ArgumentNullException

targetUri or relationshipType is a null reference (Nothing in Visual Basic).

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.

  • Between a source PackagePart to a target PackagePart inside the Package.

  • 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

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.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.