Package.GetRelationshipsByType(String) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne une collection de toutes les relations au niveau du package correspondant à un RelationshipType donné.
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
Paramètres
- relationshipType
- String
RelationshipType à faire correspondre et à retourner dans la collection.
Retours
Collection de relations au niveau du package correspondant au relationshipType
spécifié.
Exceptions
relationshipType
a la valeur null
.
relationshipType
est une chaîne vide.
Le package n'est pas ouvert (Dispose(Boolean) ou Close() a été appelée).
Le package est en écriture seule.
Exemples
L’exemple suivant montre comment récupérer les relations qui ont été définies pour le package.
// 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.
Remarques
GetRelationships ne retourne null
jamais ; toutefois, la collection retournée peut contenir zéro élément s’il n’existe aucune relation au niveau du package qui correspond au spécifié relationshipType
.
Le tableau suivant présente les URI au niveau relationshipType
du package définis par la spécification OPC (Open Packaging Conventions).
Relation au niveau du package | URI de type de relation |
---|---|
Propriétés principales | http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties |
Signature numérique | http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature |
Certificat de signature numérique | http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/certificate |
Origine de la signature numérique | http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin |
Thumbnail | http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail |
Pour plus d’informations, consultez la spécification Opc (Open Packaging Conventions) disponible en téléchargement à l’adresse https://www.ecma-international.org/publications-and-standards/standards/ecma-376/.