ZipPackage 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
추상 Package 기본 클래스의 파생 하위 클래스를 구현합니다. 클래스는 ZipPackage ZIP 보관 파일을 컨테이너 저장소로 사용합니다. 이 클래스는 상속할 수 없습니다.
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
- 상속
예제
이 예제에서는 기본 ZipPackage을 만드는 방법을 보여줍니다.
이 예제에서는 패키지 수준에서 PackageRelationship패키지의 루트 요소로 정의된 단일 문서 파트를 포함하는 패키지를 만듭니다.
패키지에는 원본 문서 부분과 대상 이미지 부분 간의 연결을 정의하는 이미지 파트와 초 PackageRelationship 가 포함되어 있습니다. (이미지는 문서와 함께 사용되는 리소스입니다).
// -------------------------- 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
' --------------------------- 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
설명
패키지입니다.Open 메서드는 기본적으로 컨테이너를 사용합니다ZipPackage.
속성
| Name | Description |
|---|---|
| FileOpenAccess |
패키지에 대한 파일 액세스 설정을 가져옵니다. (다음에서 상속됨 Package) |
| PackageProperties |
패키지의 핵심 속성을 가져옵니다. (다음에서 상속됨 Package) |
메서드
| Name | Description |
|---|---|
| Close() |
패키지와 모든 기본 파트 스트림을 저장하고 닫습니다. (다음에서 상속됨 Package) |
| CreatePart(Uri, String, CompressionOption) |
지정된 URI, 콘텐츠 형식 및 압축 옵션을 사용하여 새 파트를 만듭니다. (다음에서 상속됨 Package) |
| CreatePart(Uri, String) |
지정된 URI 및 콘텐츠 형식을 사용하여 압축되지 않은 새 파트를 만듭니다. (다음에서 상속됨 Package) |
| CreatePartCore(Uri, String, CompressionOption) |
파생 클래스에서 재정의되는 경우 패키지에 새 파트를 만듭니다. (다음에서 상속됨 Package) |
| CreateRelationship(Uri, TargetMode, String, String) |
지정된 URI, 대상 모드, 관계 유형 및 ID(식별자)를 사용하여 파트에 대한 패키지 수준 관계를 만듭니다. (다음에서 상속됨 Package) |
| CreateRelationship(Uri, TargetMode, String) |
지정된 URI, 대상 모드 및 관계 유형을 사용하여 파트에 대한 패키지 수준 관계를 만듭니다. (다음에서 상속됨 Package) |
| DeletePart(Uri) |
패키지에서 지정된 URI가 있는 파트를 삭제합니다. (다음에서 상속됨 Package) |
| DeletePartCore(Uri) |
파생 클래스에서 재정의되는 경우 지정된 URI를 사용하여 파트를 삭제합니다. (다음에서 상속됨 Package) |
| DeleteRelationship(String) |
패키지 수준 관계를 삭제합니다. (다음에서 상속됨 Package) |
| Dispose(Boolean) |
모든 파트와 관계의 콘텐츠를 플러시 및 저장하고, 패키지를 닫고, 모든 리소스를 해제합니다. (다음에서 상속됨 Package) |
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| Flush() |
패키지에 포함된 모든 파트 및 관계의 내용을 저장합니다. (다음에서 상속됨 Package) |
| FlushCore() |
파생 클래스에서 재정의되는 경우 모든 파트 및 관계의 내용을 파생 클래스 저장소에 저장합니다. (다음에서 상속됨 Package) |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetPart(Uri) |
지정된 URI를 사용하여 파트를 반환합니다. (다음에서 상속됨 Package) |
| GetPartCore(Uri) |
파생 클래스에서 재정의되는 경우 지정된 URI로 주소가 지정된 부분을 반환합니다. (다음에서 상속됨 Package) |
| GetParts() |
패키지에 있는 모든 파트의 컬렉션을 반환합니다. (다음에서 상속됨 Package) |
| GetPartsCore() |
파생 클래스에서 재정의되는 경우 패키지에 있는 모든 파트의 배열을 반환합니다. (다음에서 상속됨 Package) |
| GetRelationship(String) |
지정된 식별자를 사용하여 패키지 수준 관계를 반환합니다. (다음에서 상속됨 Package) |
| GetRelationships() |
모든 패키지 수준 관계의 컬렉션을 반환합니다. (다음에서 상속됨 Package) |
| GetRelationshipsByType(String) |
지정된 RelationshipType관계와 일치하는 모든 패키지 수준 관계의 컬렉션을 반환합니다. (다음에서 상속됨 Package) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| PartExists(Uri) |
지정된 URI를 가진 파트가 패키지에 있는지 여부를 나타냅니다. (다음에서 상속됨 Package) |
| RelationshipExists(String) |
지정된 ID를 가진 패키지 수준 관계가 패키지에 포함되어 있는지 여부를 나타냅니다. (다음에서 상속됨 Package) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| IDisposable.Dispose() |
이 멤버는 Windows Presentation Foundation(WPF) 인프라를 지원하며 애플리케이션을 사용하기 위한 것이 아닙니다. 대신 형식이 안전한 Dispose(Boolean) 메서드를 사용합니다. (다음에서 상속됨 Package) |