Package.GetRelationshipsByType(String) メソッド

定義

指定した RelationshipType に一致するすべてのパッケージ レベル リレーションシップのコレクションを返します。Returns a collection of all the package-level relationships that match a given RelationshipType.

public:
 System::IO::Packaging::PackageRelationshipCollection ^ GetRelationshipsByType(System::String ^ relationshipType);
public System.IO.Packaging.PackageRelationshipCollection GetRelationshipsByType (string relationshipType);
member this.GetRelationshipsByType : string -> System.IO.Packaging.PackageRelationshipCollection
Public Function GetRelationshipsByType (relationshipType As String) As PackageRelationshipCollection

パラメーター

relationshipType
String

コレクションで照合を行い、結果を返す RelationshipTypeThe RelationshipType to match and return in the collection.

戻り値

PackageRelationshipCollection

指定した relationshipType に一致するパッケージ レベル リレーションシップのコレクション。A collection of package-level relationships that match the specified relationshipType.

例外

relationshipTypenullです。relationshipType is null.

relationshipType が空の文字列です。relationshipType is an empty string.

パッケージが開いていません (Dispose(Boolean) または Close() が呼び出されました)。The package is not open (Dispose(Boolean) or Close() has been called).

パッケージは書き込み専用です。The package is write-only.

次の例では、パッケージに定義されているリレーションシップを取得する方法を示します。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 package =
    Package.Open(packagePath, FileMode.Open, FileAccess.Read))
{
    PackagePart documentPart = null;
    PackagePart resourcePart = null;

    // Get the Package Relationships and look for
    //   the Document part based on the RelationshipType
    Uri uriDocumentTarget = null;
    foreach (PackageRelationship relationship 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);
    }

    // Get the Document part's Relationships,
    //   and look for required resources.
    Uri uriResourceTarget = null;
    foreach (PackageRelationship relationship 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);
    }
}// end:using(Package package) - Close & dispose package.
' 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.

注釈

GetRelationshipsはを返しません null 。ただし、指定したに一致するパッケージレベルのリレーションシップがない場合、返されるコレクションには0個の要素が含まれる可能性があります。 relationshipTypeGetRelationships will never return null; however the returned collection may contain zero elements if there are no package-level relationships that match the specified relationshipType.

次の表は、 relationshipType Open パッケージング規則 (OPC) 仕様で定義されているパッケージレベルの uri を示しています。The following table shows the package-level relationshipType URIs defined by the Open Packaging Conventions (OPC) specification.

パッケージレベルのリレーションシップPackage-level Relationship リレーションシップの種類の URIRelationship Type URI
コアプロパティCore Properties http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties
デジタル署名Digital Signature http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature
デジタル署名証明書Digital Signature Certificate http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/certificate
デジタル署名の配信元Digital Signature Origin http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin
サムネイルThumbnail http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail

詳細については、でダウンロードできる Open パッケージング規則 (OPC) 仕様を参照してください https://go.microsoft.com/fwlink/?LinkID=71255For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

適用対象

こちらもご覧ください