ZipPackage ZipPackage ZipPackage ZipPackage Class

정의

Package 추상 기본 클래스의 파생 서브클래스를 구현합니다. ZipPackage 클래스는 ZIP 보관 파일을 컨테이너 저장소로 사용합니다.Implements a derived subclass of the abstract Package base class - the ZipPackage class uses a ZIP archive as the container store. 이 클래스는 상속될 수 없습니다.This class cannot be inherited.

public ref class ZipPackage sealed : System::IO::Packaging::Package
public sealed class ZipPackage : System.IO.Packaging.Package
type ZipPackage = class
    inherit Package
Public NotInheritable Class ZipPackage
Inherits Package
상속
ZipPackageZipPackageZipPackageZipPackage

예제

이 예제를 만드는 방법을 보여 줍니다 ZipPackage합니다.This example shows how to create a basic ZipPackage.

이 예제는 패키지 수준으로 패키지의 루트 요소로 정의 된 단일 문서 파트를 포함 하는 패키지를 만들어 PackageRelationship합니다.The example creates a package that contains a single document part which is defined as the package's root element by a package-level PackageRelationship.

패키지를 이미지 부분과 두 번째 포함 PackageRelationship 소스 문서 파트와 대상 이미지 파트 간의 연결을 정의 하는 합니다.The package also contains an image part and a second PackageRelationship which defines an association between the source document part and the target image part. (이미지는 문서와 함께 사용 되는 리소스).(The image is a resource that is used with the document).

//  -------------------------- CreatePackage --------------------------
/// <summary>
///   Creates a package zip file containing specified
///   content and resource files.</summary>
private static void CreatePackage()
{
    // Convert system path and file names to Part URIs. In this example
    // Uri partUriDocument /* /Content/Document.xml */ =
    //     PackUriHelper.CreatePartUri(
    //         new Uri("Content\Document.xml", UriKind.Relative));
    // Uri partUriResource /* /Resources/Image1.jpg */ =
    //     PackUriHelper.CreatePartUri(
    //         new Uri("Resources\Image1.jpg", UriKind.Relative));
    Uri partUriDocument = PackUriHelper.CreatePartUri(
                              new Uri(documentPath, UriKind.Relative));
    Uri partUriResource = 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 package =
        Package.Open(packagePath, FileMode.Create))
    {
        // 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 a Resource Part to the Package
        PackagePart packagePartResource =
            package.CreatePart(partUriResource,
                           System.Net.Mime.MediaTypeNames.Image.Jpeg);

        // Copy the data to the Resource Part
        using (FileStream fileStream = new FileStream(
               resourcePath, FileMode.Open, FileAccess.Read))
        {
            CopyStream(fileStream, packagePartResource.GetStream());
        }// 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 (Package package) - Close and dispose package.

}// end:CreatePackage()


//  --------------------------- CopyStream ---------------------------
/// <summary>
///   Copies data from a source stream to a target stream.</summary>
/// <param name="source">
///   The source stream to copy from.</param>
/// <param name="target">
///   The destination stream to copy to.</param>
private static void CopyStream(Stream source, Stream target)
{
    const int bufSize = 0x1000;
    byte[] buf = new byte[bufSize];
    int bytesRead = 0;
    while ((bytesRead = source.Read(buf, 0, bufSize)) > 0)
        target.Write(buf, 0, bytesRead);
}// end:CopyStream()
'  -------------------------- 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()


'  --------------------------- CopyStream ---------------------------
''' <summary>
'''   Copies data from a source stream to a target stream.</summary>
''' <param name="source">
'''   The source stream to copy from.</param>
''' <param name="target">
'''   The destination stream to copy to.</param>
Private Shared Sub CopyStream(ByVal source As Stream, ByVal target As Stream)
    Const bufSize As Integer = &H1000
    Dim buf(bufSize - 1) As Byte
    Dim bytesRead As Integer = 0
    bytesRead = source.Read(buf, 0, bufSize)
    Do While bytesRead > 0
        target.Write(buf, 0, bytesRead)
        bytesRead = source.Read(buf, 0, bufSize)
    Loop
End Sub ' end:CopyStream()

전체 샘플을 참조 하세요 패키지 작성 샘플합니다.For the complete sample, see Writing a Package Sample.

설명

합니다 패키지합니다.OpenThe Package.Open 메서드는 ZipPackage 기본적으로 컨테이너입니다.method uses ZipPackage containers by default.

메서드

Close() Close() Close() Close()

패키지 및 모든 내부 파트 스트림을 저장하고 닫습니다.Saves and closes the package plus all underlying part streams.

(Inherited from Package)

CreatePart(Uri, String) CreatePart(Uri, String) CreatePart(Uri, String) CreatePart(Uri, String)

지정된 URI 및 콘텐츠 형식으로 압축되지 않은 새 파트를 만듭니다.Creates a new uncompressed part with a given URI and content type.

(Inherited from Package)

CreatePart(Uri, String, CompressionOption) CreatePart(Uri, String, CompressionOption) CreatePart(Uri, String, CompressionOption) CreatePart(Uri, String, CompressionOption)

지정된 URI, 콘텐츠 형식 및 압축 옵션으로 새 파트를 만듭니다.Creates a new part with a given URI, content type, and compression option.

(Inherited from Package)

CreatePartCore(Uri, String, CompressionOption) CreatePartCore(Uri, String, CompressionOption) CreatePartCore(Uri, String, CompressionOption) CreatePartCore(Uri, String, CompressionOption)

파생 클래스에서 재정의되는 경우 패키지에서 새 파트를 만듭니다.When overridden in a derived class, creates a new part in the package.

(Inherited from Package)

CreateRelationship(Uri, TargetMode, String) CreateRelationship(Uri, TargetMode, String) CreateRelationship(Uri, TargetMode, String) CreateRelationship(Uri, TargetMode, String)

지정된 URI, 대상 모드 및 관계 형식을 가진 파트에 대한 패키지 수준 관계를 만듭니다.Creates a package-level relationship to a part with a given URI, target mode, and relationship type.

(Inherited from Package)

CreateRelationship(Uri, TargetMode, String, String) CreateRelationship(Uri, TargetMode, String, String) CreateRelationship(Uri, TargetMode, String, String) CreateRelationship(Uri, TargetMode, String, String)

지정된 URI, 대상 모드, 관계 형식 및 ID(식별자)identifier (ID)를 가진 파트에 대한 패키지 수준 관계를 만듭니다.Creates a package-level relationship to a part with a given URI, target mode, relationship type, and ID(식별자)identifier (ID).

(Inherited from Package)

DeletePart(Uri) DeletePart(Uri) DeletePart(Uri) DeletePart(Uri)

패키지에서 지정된 URI의 파트를 삭제합니다.Deletes a part with a given URI from the package.

(Inherited from Package)

DeletePartCore(Uri) DeletePartCore(Uri) DeletePartCore(Uri) DeletePartCore(Uri)

파생 클래스에서 재정의되는 경우 지정된 URI의 파트를 삭제합니다.When overridden in a derived class, deletes a part with a given URI.

(Inherited from Package)

DeleteRelationship(String) DeleteRelationship(String) DeleteRelationship(String) DeleteRelationship(String)

패키지 수준 관계를 삭제합니다.Deletes a package-level relationship.

(Inherited from Package)

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

모든 파트 및 관계의 콘텐츠를 플러시 및 저장하고, 패키지를 닫고, 모든 리소스를 해제합니다.Flushes and saves the content of all parts and relationships, closes the package, and releases all resources.

(Inherited from Package)

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)

Flush() Flush() Flush() Flush()

패키지에 포함된 모든 파트 및 관계의 콘텐츠를 저장합니다.Saves the contents of all parts and relationships that are contained in the package.

(Inherited from Package)

FlushCore() FlushCore() FlushCore() FlushCore()

파생 클래스에 재정의되는 경우 모든 파트 및 관계의 콘텐츠를 파생 클래스 저장소에 저장합니다.When overridden in a derived class, saves the content of all parts and relationships to the derived class store.

(Inherited from Package)

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)

GetPart(Uri) GetPart(Uri) GetPart(Uri) GetPart(Uri)

지정된 URI의 파트를 반환합니다.Returns the part with a given URI.

(Inherited from Package)

GetPartCore(Uri) GetPartCore(Uri) GetPartCore(Uri) GetPartCore(Uri)

파생 클래스에서 재정의되는 경우 지정된 URI로 확인되는 파트를 반환합니다.When overridden in a derived class, returns the part addressed by a given URI.

(Inherited from Package)

GetParts() GetParts() GetParts() GetParts()

패키지에 있는 모든 파트의 컬렉션을 반환합니다.Returns a collection of all the parts in the package.

(Inherited from Package)

GetPartsCore() GetPartsCore() GetPartsCore() GetPartsCore()

파생 클래스에서 재정의되는 경우 패키지에 있는 모든 파트의 배열을 반환합니다.When overridden in a derived class, returns an array of all the parts in the package.

(Inherited from Package)

GetRelationship(String) GetRelationship(String) GetRelationship(String) GetRelationship(String)

지정된 식별자를 가진 패키지 수준 관계를 반환합니다.Returns the package-level relationship with a given identifier.

(Inherited from Package)

GetRelationships() GetRelationships() GetRelationships() GetRelationships()

모든 패키지 수준 관계의 컬렉션을 반환합니다.Returns a collection of all the package-level relationships.

(Inherited from Package)

GetRelationshipsByType(String) GetRelationshipsByType(String) GetRelationshipsByType(String) GetRelationshipsByType(String)

지정된 RelationshipType에 일치하는 모든 패키지 수준 관계의 컬렉션을 반환합니다.Returns a collection of all the package-level relationships that match a given RelationshipType.

(Inherited from Package)

GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)

PartExists(Uri) PartExists(Uri) PartExists(Uri) PartExists(Uri)

지정된 URI의 파트가 패키지에 있는지 여부를 나타냅니다.Indicates whether a part with a given URI is in the package.

(Inherited from Package)

RelationshipExists(String) RelationshipExists(String) RelationshipExists(String) RelationshipExists(String)

지정된 ID의 패키지 수준 관계가 패키지에 포함되어 있는지 여부를 나타냅니다.Indicates whether a package-level relationship with a given ID is contained in the package.

(Inherited from Package)

ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

속성

FileOpenAccess FileOpenAccess FileOpenAccess FileOpenAccess

패키지의 파일 액세스 설정을 가져옵니다.Gets the file access setting for the package.

(Inherited from Package)

PackageProperties PackageProperties PackageProperties PackageProperties

패키지의 핵심 속성을 가져옵니다.Gets the core properties of the package.

(Inherited from Package)

명시적 인터페이스 구현

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

이 멤버는 WPF(Windows Presentation Foundation)Windows Presentation Foundation (WPF) 인프라를 지원하는 것으로 응용 프로그램에서는 사용하지 않는 것이 좋습니다.This member supports the WPF(Windows Presentation Foundation)Windows Presentation Foundation (WPF) infrastructure and is not intended for application use. 형식이 안전한 Dispose(Boolean) 메서드를 대신 사용하세요.Use the type-safe Dispose(Boolean) method instead.

(Inherited from Package)

적용 대상

추가 정보