Package.CreateRelationship Metoda

Definicja

Tworzy relację na poziomie pakietu z daną częścią.

Przeciążenia

CreateRelationship(Uri, TargetMode, String)

Tworzy relację na poziomie pakietu ze częścią z danym identyfikatorem URI, trybem docelowym i typem relacji.

CreateRelationship(Uri, TargetMode, String, String)

Tworzy relację na poziomie pakietu z częścią z danym identyfikatorem URI, trybem docelowym, typem relacji i identyfikatorem (ID).

Przykłady

Poniższy przykład ilustruje tworzenie PackageRelationship między częścią dokumentu głównego a Package elementem głównym.

// 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);
' Add the Document part to the Package
Dim packagePartDocument As PackagePart = package.CreatePart(partUriDocument, System.Net.Mime.MediaTypeNames.Text.Xml)

' Copy the data to the Document Part
Using fileStream As New FileStream(documentPath, FileMode.Open, FileAccess.Read)
    CopyStream(fileStream, packagePartDocument.GetStream())
End Using ' end:using(fileStream) - Close and dispose fileStream.

' Add a Package Relationship to the Document Part
package.CreateRelationship(packagePartDocument.Uri, TargetMode.Internal, PackageRelationshipType)

Uwagi

Relacja na poziomie pakietu definiuje skojarzenie między pakietem a skojarzona część docelowa lub zasób. Relacja na poziomie pakietu może być jedną z dwóch form.

W relacji package-the package pakiet jest uważany za "właściciela" relacji. Po usunięciu pakietu wszystkie relacje należące do pakietu również zostaną usunięte. Proces tworzenia lub usuwania relacji nie zmienia fizycznie części docelowej ani zasobu w żaden sposób.

Aby uzyskać dodatkowe informacje, zobacz specyfikację Open Packaging Conventions (OPC) dostępną do pobrania pod adresem https://www.ecma-international.org/publications-and-standards/standards/ecma-376/.

CreateRelationship(Uri, TargetMode, String)

Źródło:
Package.cs
Źródło:
Package.cs
Źródło:
Package.cs
Źródło:
Package.cs

Tworzy relację na poziomie pakietu ze częścią z danym identyfikatorem URI, trybem docelowym i typem relacji.

public:
 System::IO::Packaging::PackageRelationship ^ CreateRelationship(Uri ^ targetUri, System::IO::Packaging::TargetMode targetMode, System::String ^ relationshipType);
public System.IO.Packaging.PackageRelationship CreateRelationship (Uri targetUri, System.IO.Packaging.TargetMode targetMode, string relationshipType);
member this.CreateRelationship : Uri * System.IO.Packaging.TargetMode * string -> System.IO.Packaging.PackageRelationship
Public Function CreateRelationship (targetUri As Uri, targetMode As TargetMode, relationshipType As String) As PackageRelationship

Parametry

targetUri
Uri

Jednolity identyfikator zasobu (URI) części docelowej.

targetMode
TargetMode

Wskazuje, czy część docelowa jest Internal lub External do pakietu.

relationshipType
String

Identyfikator URI, który jednoznacznie definiuje rolę relacji.

Zwraca

Relacja na poziomie pakietu z określoną częścią.

Wyjątki

targetUri lub relationshipType to null.

Część targetUri to PackageRelationship, lub targetMode jest InternaltargetUri bezwzględnym identyfikatorem URI.

Wartość parametru targetMode jest nieprawidłowa.

Pakiet nie jest otwarty (Dispose(Boolean) lub Close() został wywołany).

Pakiet jest tylko do odczytu.

Przykłady

W poniższym przykładzie pokazano, jak utworzyć CreateRelationshipPackageRelationship część dokumentu głównego między elementem a Package elementem głównym.

// 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);
' Add the Document part to the Package
Dim packagePartDocument As PackagePart = package.CreatePart(partUriDocument, System.Net.Mime.MediaTypeNames.Text.Xml)

' Copy the data to the Document Part
Using fileStream As New FileStream(documentPath, FileMode.Open, FileAccess.Read)
    CopyStream(fileStream, packagePartDocument.GetStream())
End Using ' end:using(fileStream) - Close and dispose fileStream.

' Add a Package Relationship to the Document Part
package.CreateRelationship(packagePartDocument.Uri, TargetMode.Internal, PackageRelationshipType)

Uwagi

Relacja na poziomie pakietu definiuje skojarzenie między pakietem a skojarzona część docelowa lub zasób. Relacja na poziomie pakietu może być jedną z dwóch form.

  • Package Między częścią docelową w pakiecie.
  • Package Między zasobem docelowym a poza pakietem.

W relacji package-the package pakiet jest uważany za "właściciela" relacji. Po usunięciu pakietu wszystkie relacje należące do pakietu również zostaną usunięte.

CreateRelationship nie zmienia fizycznie części docelowej ani zasobu w żaden sposób.

Element docelowy relacji nie może być inną relacją.

Jeśli targetMode jest określony jako Internal, targetUri musi być względnym identyfikatorem URI utworzonym zgodnie ze specyfikacją składni ogólnej RFC 3986 Uniform Resource Identifier (URI). Wewnętrzny względny identyfikator URI może być ścieżką bezwzględną rozpoczynającą się od znaku ukośnika (/"), takiego jak "/page1.xaml" lub "/images/picture4.jpg", albo ścieżki względnej, takiej jak ".. /imagespicture1.jpg", który jest rozpoznawany względem katalogu głównego pakietu ("/") jako podstawowego identyfikatora URI.

Jeśli targetMode jest określony jako External, targetUri może być bezwzględnym lub względnym identyfikatorem URI utworzonym zgodnie ze specyfikacją składni ogólnej identyfikatora URI ( RFC 3986 Uniform Resource Identifier). http://www.microsoft.com/page2.xml jest przykładem bezwzględnego identyfikatora URI, który odwołuje się do zewnętrznego zasobu docelowego "page2.xml". "images/picture1.jpg" to przykład względnego identyfikatora URI, który odwołuje się również do zewnętrznego zasobu docelowego "1.jpg", ale który rozpoznaje identyfikator URI samego pakietu.

relationshipType musi być identyfikatorem URI utworzonym zgodnie ze specyfikacją składni ogólnej identyfikatora URI (URI) standardowego identyfikatora zasobu RFC 3986 . W poniższej tabeli przedstawiono identyfikatory URI na poziomie relationshipType pakietu zdefiniowane przez specyfikację Open Packaging Conventions (OPC).

Relacja na poziomie pakietu Identyfikator URI typu relacji
Właściwości podstawowe http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties
Podpis cyfrowy http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature
Certyfikat podpisu cyfrowego http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/certificate
Pochodzenie podpisu cyfrowego http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin
Miniaturę http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail

Aby uzyskać więcej informacji na temat tworzenia pakietów i relacji pakietów, zobacz sekcję 1.3 specyfikacji Open Packaging Conventions (OPC) dostępnej do pobrania pod adresem https://www.ecma-international.org/publications-and-standards/standards/ecma-376/.

Zobacz też

Dotyczy

CreateRelationship(Uri, TargetMode, String, String)

Źródło:
Package.cs
Źródło:
Package.cs
Źródło:
Package.cs
Źródło:
Package.cs

Tworzy relację na poziomie pakietu z częścią z danym identyfikatorem URI, trybem docelowym, typem relacji i identyfikatorem (ID).

public:
 System::IO::Packaging::PackageRelationship ^ CreateRelationship(Uri ^ targetUri, System::IO::Packaging::TargetMode targetMode, System::String ^ relationshipType, System::String ^ id);
public System.IO.Packaging.PackageRelationship CreateRelationship (Uri targetUri, System.IO.Packaging.TargetMode targetMode, string relationshipType, string? id);
public System.IO.Packaging.PackageRelationship CreateRelationship (Uri targetUri, System.IO.Packaging.TargetMode targetMode, string relationshipType, string id);
member this.CreateRelationship : Uri * System.IO.Packaging.TargetMode * string * string -> System.IO.Packaging.PackageRelationship
Public Function CreateRelationship (targetUri As Uri, targetMode As TargetMode, relationshipType As String, id As String) As PackageRelationship

Parametry

targetUri
Uri

Jednolity identyfikator zasobu (URI) części docelowej.

targetMode
TargetMode

Wskazuje, czy część docelowa jest Internal lub External do pakietu.

relationshipType
String

Identyfikator URI, który jednoznacznie definiuje rolę relacji.

id
String

Unikatowy identyfikator XML.

Zwraca

Relacja na poziomie pakietu z określoną częścią.

Wyjątki

targetUri lub relationshipType to null.

Część targetUri to PackageRelationship, lub targetMode jest InternaltargetUri bezwzględnym identyfikatorem URI.

Wartość parametru targetMode jest nieprawidłowa.

Pakiet nie jest otwarty (Dispose(Boolean) lub Close() został wywołany).

Pakiet jest tylko do odczytu.

id nie jest prawidłowym identyfikatorem XML; lub część z określonymi id już występuje w pakiecie.

Przykłady

W poniższym przykładzie pokazano, jak utworzyć CreateRelationshipPackageRelationship część dokumentu głównego między elementem a Package elementem głównym.

// 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);
' Add the Document part to the Package
Dim packagePartDocument As PackagePart = package.CreatePart(partUriDocument, System.Net.Mime.MediaTypeNames.Text.Xml)

' Copy the data to the Document Part
Using fileStream As New FileStream(documentPath, FileMode.Open, FileAccess.Read)
    CopyStream(fileStream, packagePartDocument.GetStream())
End Using ' end:using(fileStream) - Close and dispose fileStream.

' Add a Package Relationship to the Document Part
package.CreateRelationship(packagePartDocument.Uri, TargetMode.Internal, PackageRelationshipType)

Uwagi

Relacja na poziomie pakietu definiuje skojarzenie między pakietem a skojarzona część docelowa lub zasób. Relacja na poziomie pakietu może być jedną z dwóch form.

  • Package Między częścią docelową w pakiecie.
  • Package Między zasobem docelowym a poza pakietem.

W relacji package-the package pakiet jest uważany za "właściciela" relacji. Po usunięciu pakietu wszystkie relacje należące do pakietu również zostaną usunięte.

CreateRelationship nie zmienia fizycznie części docelowej ani zasobu w żaden sposób.

Element docelowy relacji nie może być inną relacją.

id musi być prawidłowym identyfikatorem XML. Typ id to xsd:ID i musi być zgodny z konwencjami nazewnictwa określonymi w specyfikacji Schemat XML Część 2: Datatypes (patrz https://www.w3.org/TR/xmlschema-2/#ID).

Jeśli id zostanie określony jako null unikatowy identyfikator, zostanie wygenerowany automatycznie. Wartość określona id przez pusty ciąg jest nieprawidłowa.

Jeśli targetMode jest określony jako Internal, targetUri musi być względnym identyfikatorem URI utworzonym zgodnie ze specyfikacją składni ogólnej RFC 3986 Uniform Resource Identifier (URI). Wewnętrzny względny identyfikator URI może być ścieżką bezwzględną rozpoczynającą się od znaku ukośnika (/"), takiego jak "/page1.xaml" lub "/images/picture4.jpg", albo ścieżki względnej, takiej jak ".. /imagespicture1.jpg", który jest rozpoznawany względem katalogu głównego pakietu ("/") jako podstawowego identyfikatora URI.

Jeśli targetMode jest określony jako External, targetUri może być bezwzględnym lub względnym identyfikatorem URI utworzonym zgodnie ze specyfikacją składni ogólnej identyfikatora URI ( RFC 3986 Uniform Resource Identifier). http://www.microsoft.com/page2.xml jest przykładem bezwzględnego identyfikatora URI, który odwołuje się do zewnętrznego zasobu docelowego "page2.xml". "images/picture1.jpg" to przykład względnego identyfikatora URI, który odwołuje się również do zewnętrznego zasobu docelowego "1.jpg", ale który rozpoznaje identyfikator URI samego pakietu.

relationshipType musi być identyfikatorem URI utworzonym zgodnie ze specyfikacją składni ogólnej identyfikatora URI (URI) standardowego identyfikatora zasobu RFC 3986 . W poniższej tabeli przedstawiono identyfikatory URI na poziomie relationshipType pakietu zdefiniowane przez specyfikację Open Packaging Conventions (OPC).

Relacja na poziomie pakietu Identyfikator URI typu relacji
Właściwości podstawowe http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties
Podpis cyfrowy http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature
Certyfikat podpisu cyfrowego http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/certificate
Pochodzenie podpisu cyfrowego http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin
Miniaturę http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail

Aby uzyskać dodatkowe informacje na temat tworzenia pakietów i relacji pakietów, zobacz sekcję 1.3 specyfikacji Open Packaging Conventions (OPC) dostępnej do pobrania pod adresem https://www.ecma-international.org/publications-and-standards/standards/ecma-376/.

Zobacz też

Dotyczy