Package.GetRelationshipsByType(String) Methode

Definitie

Hiermee wordt een verzameling geretourneerd van alle relaties op pakketniveau die overeenkomen met een bepaalde RelationshipTyperelatie.

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

Parameters

relationshipType
String

De RelationshipType overeenkomst en retourneer in de verzameling.

Retouren

Een verzameling relaties op pakketniveau die overeenkomen met de opgegeven relationshipType.

Uitzonderingen

relationshipType is null.

relationshipType is een lege tekenreeks.

Het pakket is niet geopend (Dispose(Boolean) of Close() is aangeroepen).

Het pakket is alleen-schrijven.

Voorbeelden

In het volgende voorbeeld ziet u hoe u de relaties ophaalt die zijn gedefinieerd voor het pakket.

// 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.

Opmerkingen

GetRelationships retourneert nooit null; de geretourneerde verzameling kan echter nulelementen bevatten als er geen relaties op pakketniveau zijn die overeenkomen met de opgegeven relationshipType.

In de volgende tabel ziet u de URI's op pakketniveau relationshipType die zijn gedefinieerd door de OPC-specificatie (Open Packaging Conventions).

Relatie op pakketniveau Relatietype-URI
Kerneigenschappen http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties
Digitale handtekening http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature
Certificaat voor digitale handtekening http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/certificate
Oorsprong van digitale handtekening http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin
Miniatuurafbeelding http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail

Zie de OPC-specificatie (Open Packaging Conventions) die u kunt downloaden voor https://www.ecma-international.org/publications-and-standards/standards/ecma-376/meer informatie.

Van toepassing op

Zie ook