This documentation is archived and is not being maintained.

Package.CreateRelationship Method

Creates a package-level relationship to a given part.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

Public method CreateRelationship(Uri, TargetMode, String) Creates a package-level relationship to a part with a given URI, target mode, and relationship type.
Public method CreateRelationship(Uri, TargetMode, String, String) Creates a package-level relationship to a part with a given URI, target mode, relationship type, and identifier (ID).

A package-level relationship defines an association between the package and an associated target part or resource. A package-level relationship can be one of two forms.

In a package-relationship the package is considered the "owner" of the relationship. When the package is deleted, all the relationships owned by the package are also deleted. The process of creating or deleting the relationship does not physically alter the target part or resource in any way.

For additional information, see the Open Packaging Conventions (OPC) specification available for download at

The following example illustrates creating a PackageRelationship between a Package and a root document part. For the complete sample, see Writing a Package Sample.

// Add the Document part to the Package
PackagePart packagePartDocument =

// Copy the data to the Document Part
using (FileStream fileStream = new FileStream(
       documentPath, FileMode.Open, FileAccess.Read))
    CopyStream(fileStream, packagePartDocument.GetStream());
}// end:using(fileStream) - Close and dispose fileStream.

// Add a Package Relationship to the Document Part