Package.Open Package.Open Package.Open Package.Open Method

정의

패키지를 엽니다.Opens a package.

오버로드

Open(Stream) Open(Stream) Open(Stream)

지정된 IO 스트림에서 패키지를 엽니다.Opens a package on a given IO stream.

Open(String) Open(String) Open(String) Open(String)

지정된 경로 및 파일 이름에서 패키지를 엽니다.Opens a package at a given path and file name.

Open(Stream, FileMode) Open(Stream, FileMode) Open(Stream, FileMode)

지정된 IO 스트림 및 파일 모드를 사용하여 패키지를 엽니다.Opens a package with a given IO stream and file mode.

Open(String, FileMode) Open(String, FileMode) Open(String, FileMode) Open(String, FileMode)

지정된 경로의 패키지를 지정된 파일 모드를 사용하여 엽니다.Opens a package at a given path using a given file mode.

Open(Stream, FileMode, FileAccess) Open(Stream, FileMode, FileAccess) Open(Stream, FileMode, FileAccess)

지정된 IO 스트림, 파일 모드 및 파일 액세스 설정을 사용하여 패키지를 엽니다.Opens a package with a given IO stream, file mode, and file access setting.

Open(String, FileMode, FileAccess) Open(String, FileMode, FileAccess) Open(String, FileMode, FileAccess) 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) Open(String, FileMode, FileAccess, FileShare) Open(String, FileMode, FileAccess, FileShare) Open(String, FileMode, FileAccess, FileShare)

지정된 경로의 패키지를 지정된 파일 모드, 파일 액세스 및 파일 공유 설정을 사용하여 엽니다.Opens a package at a given path using a given file mode, file access, and file share setting.

예제

다음 예제에서는 새로 만드는 방법을 보여 줍니다 Package 를 통합 하는 PackageRelationshipPackagePart 저장 된 데이터와 함께 요소입니다.The following example shows how to create a new Package that incorporates PackageRelationship and PackagePart elements together with stored data. 전체 샘플을 참조 하세요 패키지 작성 샘플합니다.For the complete sample, see Writing a Package Sample.

//  -------------------------- 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()

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

Open(Stream) Open(Stream) Open(Stream)

지정된 IO 스트림에서 패키지를 엽니다.Opens a package on a given IO stream.

public:
 static System::IO::Packaging::Package ^ Open(System::IO::Stream ^ stream);
public static System.IO.Packaging.Package Open (System.IO.Stream stream);
static member Open : System.IO.Stream -> System.IO.Packaging.Package

매개 변수

stream
Stream Stream Stream Stream

패키지를 열 IO 스트림입니다.The IO stream on which to open the package.

반환

열린 패키지입니다.The opened package.

예외

열려는 패키지에 읽기 또는 읽기/쓰기 권한이 필요하고 지정된 stream이 읽기 전용인 경우 또는 열려는 패키지에 쓰기 또는 읽기/쓰기 권한이 필요하고 지정된 stream이 읽기 전용인 경우The package to open requires read or read/write permission and the specified stream is write-only; or, the package to open requires write or read/write permission and the specified stream is read-only.

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

Open(String) Open(String) Open(String) Open(String)

지정된 경로 및 파일 이름에서 패키지를 엽니다.Opens a package at a given path and file name.

public:
 static System::IO::Packaging::Package ^ Open(System::String ^ path);
public static System.IO.Packaging.Package Open (string path);
static member Open : string -> System.IO.Packaging.Package
Public Shared Function Open (path As String) As Package

매개 변수

path
String String String String

패키지의 경로 및 파일 이름입니다.The path and file name of the package.

반환

열린 패키지입니다.The opened package.

예외

예제

다음 예제에서는 새로 만드는 방법을 보여 줍니다 Package 를 통합 하는 PackageRelationshipPackagePart 저장 된 데이터와 함께 요소입니다.The following example shows how to create a new Package that incorporates PackageRelationship and PackagePart elements together with stored data. 전체 샘플을 참조 하세요 패키지 작성 샘플합니다.For the complete sample, see Writing a Package Sample.

//  -------------------------- 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()

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

Open 메서드는 기본 특성을 사용 하 여 패키지를 엽니다 OpenOrCreate, ReadWrite, 및 None (되도록 서로 다른 특성을 사용 하 여 다른 Open 메서드 오버 로드 중 하나).This Open method opens the package with default attributes OpenOrCreate, ReadWrite, and None (to specify different attributes use one of the other Open method overloads).

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

Open(Stream, FileMode) Open(Stream, FileMode) Open(Stream, FileMode)

지정된 IO 스트림 및 파일 모드를 사용하여 패키지를 엽니다.Opens a package with a given IO stream and file mode.

public:
 static System::IO::Packaging::Package ^ Open(System::IO::Stream ^ stream, System::IO::FileMode packageMode);
public static System.IO.Packaging.Package Open (System.IO.Stream stream, System.IO.FileMode packageMode);
static member Open : System.IO.Stream * System.IO.FileMode -> System.IO.Packaging.Package

매개 변수

stream
Stream Stream Stream Stream

패키지를 열 IO 스트림입니다.The IO stream on which to open the package.

packageMode
FileMode FileMode FileMode FileMode

패키지를 열 때 사용할 파일 모드입니다.The file mode in which to open the package.

반환

열린 패키지입니다.The opened package.

예외

packageMode 값이 잘못된 경우packageMode value is not valid.

열려는 패키지에 읽기 또는 읽기/쓰기 권한이 필요하고 지정된 stream이 읽기 전용인 경우 또는 열려는 패키지에 쓰기 또는 읽기/쓰기 권한이 필요하고 지정된 stream이 읽기 전용인 경우The package to open requires read or read/write permission and the specified stream is write-only; or, the package to open requires write or read/write permission and the specified stream is read-only.

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

Open(String, FileMode) Open(String, FileMode) Open(String, FileMode) Open(String, FileMode)

지정된 경로의 패키지를 지정된 파일 모드를 사용하여 엽니다.Opens a package at a given path using a given file mode.

public:
 static System::IO::Packaging::Package ^ Open(System::String ^ path, System::IO::FileMode packageMode);
public static System.IO.Packaging.Package Open (string path, System.IO.FileMode packageMode);
static member Open : string * System.IO.FileMode -> System.IO.Packaging.Package
Public Shared Function Open (path As String, packageMode As FileMode) As Package

매개 변수

path
String String String String

패키지의 경로 및 파일 이름입니다.The path and file name of the package.

packageMode
FileMode FileMode FileMode FileMode

패키지를 열 때 사용할 파일 모드입니다.The file mode in which to open the package.

반환

열린 패키지입니다.The opened package.

예외

packageMode의 값이 올바르지 않은 경우Value for packageMode is not valid.

예제

다음 예제에서는 새로 만드는 방법을 보여 줍니다 Package 를 통합 하는 PackageRelationshipPackagePart 저장 된 데이터와 함께 요소입니다.The following example shows how to create a new Package that incorporates PackageRelationship and PackagePart elements together with stored data. 전체 샘플을 참조 하세요 패키지 작성 샘플합니다.For the complete sample, see Writing a Package Sample.

//  -------------------------- 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()

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

이렇게 Open 메서드는 기본 특성을 사용 하 여 패키지를 엽니다 ReadWriteNone (서로 다른 특성을 사용 하 여 다른 Open 메서드 오버 로드 중 하나를 지정) 하 합니다.This Open method opens the package with default attributes ReadWrite and None (to specify different attributes use one of the other Open method overloads).

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

Open(Stream, FileMode, FileAccess) Open(Stream, FileMode, FileAccess) Open(Stream, FileMode, FileAccess)

지정된 IO 스트림, 파일 모드 및 파일 액세스 설정을 사용하여 패키지를 엽니다.Opens a package with a given IO stream, file mode, and file access setting.

public:
 static System::IO::Packaging::Package ^ Open(System::IO::Stream ^ stream, System::IO::FileMode packageMode, System::IO::FileAccess packageAccess);
public static System.IO.Packaging.Package Open (System.IO.Stream stream, System.IO.FileMode packageMode, System.IO.FileAccess packageAccess);
static member Open : System.IO.Stream * System.IO.FileMode * System.IO.FileAccess -> System.IO.Packaging.Package

매개 변수

stream
Stream Stream Stream Stream

패키지를 열 IO 스트림입니다.The IO stream on which to open the package.

packageMode
FileMode FileMode FileMode FileMode

패키지를 열 때 사용할 파일 모드입니다.The file mode in which to open the package.

packageAccess
FileAccess FileAccess FileAccess FileAccess

패키지를 열 때 사용할 파일 액세스 권한입니다.The file access in which to open the package.

반환

열린 패키지입니다.The opened package.

예외

packageMode 또는 packageAccess의 값이 올바르지 않은 경우The value for packageMode or packageAccess is not valid.

열려는 패키지에 읽기 또는 읽기/쓰기 권한이 필요하고 지정된 stream이 읽기 전용인 경우 또는 열려는 패키지에 쓰기 또는 읽기/쓰기 권한이 필요하고 지정된 stream이 읽기 전용인 경우The package to open requires read or read/write permission and the specified stream is write-only; or the package to open requires write or read/write permission and the specified stream is read-only.

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

Open(String, FileMode, FileAccess) Open(String, FileMode, FileAccess) Open(String, FileMode, FileAccess) Open(String, FileMode, FileAccess)

지정된 경로의 패키지를 지정된 파일 모드 및 파일 액세스 설정을 사용하여 엽니다.Opens a package at a given path using a given file mode and file access setting.

public:
 static System::IO::Packaging::Package ^ Open(System::String ^ path, System::IO::FileMode packageMode, System::IO::FileAccess packageAccess);
public static System.IO.Packaging.Package Open (string path, System.IO.FileMode packageMode, System.IO.FileAccess packageAccess);
static member Open : string * System.IO.FileMode * System.IO.FileAccess -> System.IO.Packaging.Package
Public Shared Function Open (path As String, packageMode As FileMode, packageAccess As FileAccess) As Package

매개 변수

path
String String String String

패키지의 경로 및 파일 이름입니다.The path and file name of the package.

packageMode
FileMode FileMode FileMode FileMode

패키지를 열 때 사용할 파일 모드입니다.The file mode in which to open the package.

packageAccess
FileAccess FileAccess FileAccess FileAccess

패키지를 열 때 사용할 파일 액세스 권한입니다.The file access in which to open the package.

반환

열린 패키지입니다.The opened package.

예외

packageMode 또는 packageAccess의 값이 올바르지 않은 경우Value for packageMode or packageAccess is not valid.

예제

다음 예제에서는 열고 읽는 방법을 Package 포함 된 PackageRelationshipPackagePart 저장 된 데이터와 함께 요소입니다.The following example shows how to open and read a Package that contains PackageRelationship and PackagePart elements together with stored data. 전체 샘플을 참조 하세요 는 패키지 예제 추가 정보를 읽는합니다.For the complete sample, see Reading a Package Sample.

// 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.

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

Open 메서드는 기본값을 사용 하 여 패키지를 엽니다 None 특성 (다른 특성 사용법을 지정 하는 Open 메서드 오버 로드).This Open method opens the package with a default None attribute (to specify a different attribute use the Open method overload).

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

Open(String, FileMode, FileAccess, FileShare) Open(String, FileMode, FileAccess, FileShare) Open(String, FileMode, FileAccess, FileShare) Open(String, FileMode, FileAccess, FileShare)

지정된 경로의 패키지를 지정된 파일 모드, 파일 액세스 및 파일 공유 설정을 사용하여 엽니다.Opens a package at a given path using a given file mode, file access, and file share setting.

public:
 static System::IO::Packaging::Package ^ Open(System::String ^ path, System::IO::FileMode packageMode, System::IO::FileAccess packageAccess, System::IO::FileShare packageShare);
public static System.IO.Packaging.Package Open (string path, System.IO.FileMode packageMode, System.IO.FileAccess packageAccess, System.IO.FileShare packageShare);
static member Open : string * System.IO.FileMode * System.IO.FileAccess * System.IO.FileShare -> System.IO.Packaging.Package
Public Shared Function Open (path As String, packageMode As FileMode, packageAccess As FileAccess, packageShare As FileShare) As Package

매개 변수

path
String String String String

패키지의 경로 및 파일 이름입니다.The path and file name of the package.

packageMode
FileMode FileMode FileMode FileMode

패키지를 열 때 사용할 파일 모드입니다.The file mode in which to open the package.

packageAccess
FileAccess FileAccess FileAccess FileAccess

패키지를 열 때 사용할 파일 액세스 권한입니다.The file access in which to open the package.

packageShare
FileShare FileShare FileShare FileShare

패키지를 열 때 사용할 파일 공유 모드입니다.The file sharing mode in which to open the package.

반환

열린 패키지입니다.The opened package.

예외

packageMode, packageAccess 또는 packageShare의 값이 올바르지 않은 경우The value for packageMode, packageAccess, or packageShare is not valid.

예제

다음 예제에서는 새로 만드는 방법을 보여 줍니다 Package 를 통합 하는 PackageRelationshipPackagePart 저장 된 데이터와 함께 요소입니다.The following example shows how to create a new Package that incorporates PackageRelationship and PackagePart elements together with stored data. 전체 샘플을 참조 하세요 패키지 작성 샘플합니다.For the complete sample, see Writing a Package Sample.

//  -------------------------- 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()

설명

ZipPackage 사용 되는 기본 패키지 형식는 Open 메서드.ZipPackage is the default package type that is used by the Open method.

자세한 내용은에서 다운로드할 수 있는 OPC Open Packaging Conventions () 사양을 참조 https://go.microsoft.com/fwlink/?LinkID=71255합니다.For additional information, see the Open Packaging Conventions (OPC) specification available for download at https://go.microsoft.com/fwlink/?LinkID=71255.

적용 대상