Export (0) Print
Expand All

Package.GetRelationshipsByType Method

Returns a collection of all the package-level relationships that match a given RelationshipType.

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

Public Function GetRelationshipsByType ( _
	relationshipType As String _
) As PackageRelationshipCollection


Type: System.String

The RelationshipType to match and return in the collection.

Return Value

Type: System.IO.Packaging.PackageRelationshipCollection
A collection of package-level relationships that match the specified relationshipType.


relationshipType is Nothing.


relationshipType is an empty string.


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


The package is write-only.

GetRelationships will never return Nothing; however the returned collection may contain zero elements if there are no package-level relationships that match the specified relationshipType.

The following table shows the package-level relationshipType URIs defined by the Open Packaging Conventions (OPC) specification.

Package-level Relationship

Relationship Type URI

Core Properties

http://schemas.openxmlformats.org/package/2006/relationships/meta data/core-properties

Digital Signature

http://schemas.openxmlformats.org/package/2006/relationships/digit al-signature/signature

Digital Signature Certificate

http://schemas.openxmlformats.org/package/2006/relationships/digit al-signature/certificate

Digital Signature Origin

http://schemas.openxmlformats.org/package/2006/relationships/digit al-signature/origin


http://schemas.openxmlformats.org/package/2006/relationships/meta data/thumbnail

For additional information, see the Open Packaging Conventions (OPC) specification available for download at http://go.microsoft.com/fwlink/?LinkID=71255.

The following example shows how to retrieve the relationships that have been defined for the package. For the complete sample, see Reading a Package Sample.

			' Open the Package.
			' ('using' statement insures that 'package' is
			'  closed and disposed when it goes out of scope.)
			Using package As Package = Package.Open(packagePath, FileMode.Open, FileAccess.Read)
				Dim documentPart As PackagePart = Nothing
				Dim resourcePart As PackagePart = Nothing

				' Get the Package Relationships and look for
				'   the Document part based on the RelationshipType
				Dim uriDocumentTarget As Uri = Nothing
				For Each relationship As PackageRelationship In package.GetRelationshipsByType(PackageRelationshipType)
					' Resolve the Relationship Target Uri
					'   so the Document Part can be retrieved.
					uriDocumentTarget = PackUriHelper.ResolvePartUri(New Uri("/", UriKind.Relative), relationship.TargetUri)

					' Open the Document Part, write the contents to a file.
					documentPart = package.GetPart(uriDocumentTarget)
					ExtractPart(documentPart, targetDirectory)
				Next relationship

				' Get the Document part's Relationships,
				'   and look for required resources.
				Dim uriResourceTarget As Uri = Nothing
				For Each relationship As PackageRelationship In documentPart.GetRelationshipsByType(ResourceRelationshipType)
					' Resolve the Relationship Target Uri
					'   so the Resource Part can be retrieved.
					uriResourceTarget = PackUriHelper.ResolvePartUri(documentPart.Uri, relationship.TargetUri)

					' Open the Resource Part and write the contents to a file.
					resourcePart = package.GetPart(uriResourceTarget)
					ExtractPart(resourcePart, targetDirectory)
				Next relationship

			End Using ' end:using(Package package) - Close & dispose package.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft