Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

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.

  Name Description
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).
Top

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 http://go.microsoft.com/fwlink/?LinkID=71255.

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 =
    package.CreatePart(partUriDocument,
                   System.Net.Mime.MediaTypeNames.Text.Xml);

// 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
package.CreateRelationship(packagePartDocument.Uri,
                           TargetMode.Internal,
                           PackageRelationshipType);
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.