Represents a container that can store multiple data objects.
Assembly: WindowsBase (in WindowsBase.dll)
Thetype exposes the following members.
|Close||Saves and closes the package plus all underlying part streams.|
|CreatePart(Uri, String)||Creates a new uncompressed part with a given URI and content type.|
|CreatePart(Uri, String, CompressionOption)||Creates a new part with a given URI, content type, and compression option.|
|CreatePartCore||When overridden in a derived class, creates a new part in the package.|
|CreateRelationship(Uri, TargetMode, String)||Creates a package-level relationship to a part with a given URI, target mode, and relationship type.|
|CreateRelationship(Uri, TargetMode, String, String)||Creates a package-level relationship to a part with a given URI, target mode, relationship type, and identifier (ID).|
|DeletePart||Deletes a part with a given URI from the package.|
|DeletePartCore||When overridden in a derived class, deletes a part with a given URI.|
|DeleteRelationship||Deletes a package-level relationship.|
|Dispose||Flushes and saves the content of all parts and relationships, closes the package, and releases all resources.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|Flush||Saves the contents of all parts and relationships that are contained in the package.|
|FlushCore||When overridden in a derived class, saves the content of all parts and relationships to the derived class store.|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetPart||Returns the part with a given URI.|
|GetPartCore||When overridden in a derived class, returns the part addressed by a given URI.|
|GetParts||Returns a collection of all the parts in the package.|
|GetPartsCore||When overridden in a derived class, returns an array of all the parts in the package.|
|GetRelationship||Returns the package-level relationship with a given identifier.|
|GetRelationships||Returns a collection of all the package-level relationships.|
|GetRelationshipsByType||Returns a collection of all the package-level relationships that match a given RelationshipType.|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Open(Stream)||Opens a package on a given IO stream.|
|Open(String)||Opens a package at a given path and file name.|
|Open(Stream, FileMode)||Opens a package with a given IO stream and file mode.|
|Open(String, FileMode)||Opens a package at a given path using a given file mode.|
|Open(Stream, FileMode, FileAccess)||Opens a package with a given IO stream, file mode, and file access setting.|
|Open(String, FileMode, FileAccess)||Opens a package at a given path using a given file mode and file access setting.|
|Open(String, FileMode, FileAccess, FileShare)||Opens a package at a given path using a given file mode, file access, and file share setting.|
|PartExists||Indicates whether a part with a given URI is in the package.|
|RelationshipExists||Indicates whether a package-level relationship with a given ID is contained in the package.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
is an abstract class that can be used to organize objects into a single entity of a defined physical format for portability and efficient access.
A ZIP file is the primary physical format for the . Other implementations might use other physical formats such as an XML document, a database, or Web service.
Like a file system, items contained in a are referenced in a hierarchical organization of folders and files.
A PackagePart ("part") is the abstract class that represents an object that is stored in a .
A PackageRelationship ("relationship") defines an association between a source or PackagePart and a target object. A PackageRelationship can be one of two types, each of which can be one of two forms:
A package-level relationship (created by the Package.CreateRelationship method) relates a to either:
A target part in the package.
A target resource outside the package.
Another target part in the package.
A target resource outside the package.
The relationship's source or source PackagePart is considered the "owner" of the relationship. When the source object is deleted, all the relationships owned by the source object are also deleted. The process of creating or deleting a relationship does not physically change either the source or target objects in any way.
A PackageDigitalSignature ("digital signature") is a composition of parts and relationships representing a digital signature included with a . The digital signature identifies the originator and validates that the signed parts and relationships contained in the have not been modified.
Packages also support Digital Rights Management (DRM) which allows content elements in a to be encrypted with specific access rights granted to authorized users.
Microsoft .NET Framework uses packages to store content, resources, and relationships for pages and documents using a standard ZIP file by default. As with any ZIP file, your application can use the System.IO.Packaging classes to store and optionally protect any type or number of data files in a single efficient-to-access container.
For more information, see the Open Packaging Conventions (OPC) specification available for download at http://go.microsoft.com/fwlink/?LinkID=71255.
The following example shows the basic steps for creating a . In this example, a package is created to contain a document together with a graphic image that is displayed as part of the document. (This is similar to the case in which an HTML file has an <IMG> tag that references an external image file.) Two PackageRelationship elements are also included in the package. The first, a "package-level" relationship, defines the document part as the package's root element. A second, "part-level" relationship defines the association between the document part (the "source" of the part-level relationship) and its use of the image part (the "target" of the part-level relationship). For the complete sample, see Writing a Package Sample.
' -------------------------- CreatePackage -------------------------- ''' <summary> ''' Creates a package zip file containing specified ''' content and resource files.</summary> Private Shared Sub CreatePackage() ' Convert system path and file names to Part URIs. In this example ' Dim partUriDocument as Uri /* /Content/Document.xml */ = ' PackUriHelper.CreatePartUri( ' New Uri("Content\Document.xml", UriKind.Relative)) ' Dim partUriResource as Uri /* /Resources/Image1.jpg */ = ' PackUriHelper.CreatePartUri( ' New Uri("Resources\Image1.jpg", UriKind.Relative)) Dim partUriDocument As Uri = PackUriHelper.CreatePartUri(New Uri(documentPath, UriKind.Relative)) Dim partUriResource As Uri = PackUriHelper.CreatePartUri(New Uri(resourcePath, UriKind.Relative)) ' Create the Package ' (If the package file already exists, FileMode.Create will ' automatically delete it first before creating a new one. ' The 'using' statement insures that 'package' is ' closed and disposed when it goes out of scope.) Using package As Package = Package.Open(packagePath, FileMode.Create) ' 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) ' Add a Resource Part to the Package Dim packagePartResource As PackagePart = package.CreatePart(partUriResource, System.Net.Mime.MediaTypeNames.Image.Jpeg) ' Copy the data to the Resource Part Using fileStream As New FileStream(resourcePath, FileMode.Open, FileAccess.Read) CopyStream(fileStream, packagePartResource.GetStream()) End Using ' end:using(fileStream) - Close and dispose fileStream. ' Add Relationship from the Document part to the Resource part packagePartDocument.CreateRelationship(New Uri("../resources/image1.jpg", UriKind.Relative), TargetMode.Internal, ResourceRelationshipType) End Using ' end:using (Package package) - Close and dispose package. End Sub ' end:CreatePackage()
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.