ZipFileExtensions.CreateEntryFromFile 메서드

정의

파일을 압축하고 ZIP 보관 위치에 추가하여 보관합니다.

오버로드

CreateEntryFromFile(ZipArchive, String, String)

파일을 압축하고 ZIP 보관 위치에 추가하여 보관합니다.

CreateEntryFromFile(ZipArchive, String, String, CompressionLevel)

지정된 압축 수준을 사용하여 압축하고 zip 보관 저장소에 추가하여 파일을 보관합니다.

CreateEntryFromFile(ZipArchive, String, String)

Source:
ZipFileExtensions.ZipArchive.Create.cs
Source:
ZipFileExtensions.ZipArchive.Create.cs
Source:
ZipFileExtensions.ZipArchive.Create.cs

파일을 압축하고 ZIP 보관 위치에 추가하여 보관합니다.

public:
[System::Runtime::CompilerServices::Extension]
 static System::IO::Compression::ZipArchiveEntry ^ CreateEntryFromFile(System::IO::Compression::ZipArchive ^ destination, System::String ^ sourceFileName, System::String ^ entryName);
public static System.IO.Compression.ZipArchiveEntry CreateEntryFromFile (this System.IO.Compression.ZipArchive destination, string sourceFileName, string entryName);
static member CreateEntryFromFile : System.IO.Compression.ZipArchive * string * string -> System.IO.Compression.ZipArchiveEntry
<Extension()>
Public Function CreateEntryFromFile (destination As ZipArchive, sourceFileName As String, entryName As String) As ZipArchiveEntry

매개 변수

destination
ZipArchive

파일을 추가할 zip 보관 위치입니다.

sourceFileName
String

보관할 파일의 경로입니다. 상대 경로 또는 절대 경로를 지정할 수 있습니다. 상대 경로는 현재 작업 디렉터리에 상대적으로 해석됩니다.

entryName
String

zip 보관 위치에 만들 항목의 이름입니다.

반환

ZIP 보관 위치에 있는 새 항목에 대한 래퍼입니다.

예외

sourceFileNameEmpty이거나, 공백만 포함하거나 또는 잘못된 문자를 하나 이상 포함하는 경우

또는

entryName이(가) Empty인 경우

sourceFileName 또는 entryNamenull인 경우

sourceFileName에서 지정된 경로, 파일 이름 또는 둘 다가 시스템에 정의된 최대 길이를 초과하는 경우

sourceFileName가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있음).

에서 지정한 sourceFileName 파일을 열 수 없거나 너무 커서 업데이트할 수 없습니다(현재 제한은 Int32.MaxValue).

sourceFileName은 디렉터리를 지정합니다.

또는

sourceFileName에서 지정한 파일에 액세스하는 데 필요한 권한이 호출자에게 없는 경우

sourceFileName에서 지정한 파일을 찾을 수 없는 경우

sourceFileName 매개 변수의 형식이 잘못되었습니다.

또는

zip 보관 위치가 쓰기를 지원하지 않는 경우

zip 보관 위치가 삭제되었습니다.

예제

다음 예제에서는 기존 파일에서 zip 보관 파일에 새 항목을 만드는 방법을 보여 있습니다.

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string zipPath = @"c:\users\exampleuser\start.zip";
            string extractPath = @"c:\users\exampleuser\extract";
            string newFile = @"c:\users\exampleuser\NewFile.txt";

            using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Update))
            {
                archive.CreateEntryFromFile(newFile, "NewEntry.txt");
                archive.ExtractToDirectory(extractPath);
            }
        }
    }
}
Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Dim zipPath As String = "c:\users\exampleuser\end.zip"
        Dim extractPath As String = "c:\users\exampleuser\extract"
        Dim newFile As String = "c:\users\exampleuser\NewFile.txt"

        Using archive As ZipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Update)
            archive.CreateEntryFromFile(newFile, "NewEntry.txt", CompressionLevel.Fastest)
            archive.ExtractToDirectory(extractPath)
        End Using
    End Sub

End Module

설명

아카이브의 새 항목에는 로 지정된 파일의 내용이 포함됩니다 sourceFileName. 지정된 이름(entryName)이 있는 항목이 보관 파일에 이미 있는 경우 동일한 이름으로 두 번째 항목이 만들어집니다. 항목의 속성은 LastWriteTime 파일 시스템의 파일이 마지막으로 변경된 시간으로 설정됩니다.

가 있는 경우 ZipArchiveMode.Update 항목의 크기 제한은 로 Int32.MaxValue제한됩니다. 이 제한은 업데이트 모드가 내부적으로 를 MemoryStream 사용하여 보관 파일을 업데이트할 때 필요한 검색을 허용하고 MemoryStream 최대 int 크기와 같기 때문입니다.

적용 대상

CreateEntryFromFile(ZipArchive, String, String, CompressionLevel)

Source:
ZipFileExtensions.ZipArchive.Create.cs
Source:
ZipFileExtensions.ZipArchive.Create.cs
Source:
ZipFileExtensions.ZipArchive.Create.cs

지정된 압축 수준을 사용하여 압축하고 zip 보관 저장소에 추가하여 파일을 보관합니다.

public:
[System::Runtime::CompilerServices::Extension]
 static System::IO::Compression::ZipArchiveEntry ^ CreateEntryFromFile(System::IO::Compression::ZipArchive ^ destination, System::String ^ sourceFileName, System::String ^ entryName, System::IO::Compression::CompressionLevel compressionLevel);
public static System.IO.Compression.ZipArchiveEntry CreateEntryFromFile (this System.IO.Compression.ZipArchive destination, string sourceFileName, string entryName, System.IO.Compression.CompressionLevel compressionLevel);
static member CreateEntryFromFile : System.IO.Compression.ZipArchive * string * string * System.IO.Compression.CompressionLevel -> System.IO.Compression.ZipArchiveEntry
<Extension()>
Public Function CreateEntryFromFile (destination As ZipArchive, sourceFileName As String, entryName As String, compressionLevel As CompressionLevel) As ZipArchiveEntry

매개 변수

destination
ZipArchive

파일을 추가할 zip 보관 위치입니다.

sourceFileName
String

보관할 파일의 경로입니다. 상대 경로 또는 절대 경로를 지정할 수 있습니다. 상대 경로는 현재 작업 디렉터리에 상대적으로 해석됩니다.

entryName
String

zip 보관 위치에 만들 항목의 이름입니다.

compressionLevel
CompressionLevel

항목을 만들 때 속도 또는 압축 효율을 강조할지 여부를 나타내는 열거형 값 중 하나입니다.

반환

ZIP 보관 위치에 있는 새 항목에 대한 래퍼입니다.

예외

sourceFileNameEmpty이거나, 공백만 포함하거나 또는 잘못된 문자를 하나 이상 포함하는 경우

또는

entryName이(가) Empty인 경우

sourceFileName 또는 entryNamenull인 경우

sourceFileName가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있음).

sourceFileName에서 지정된 경로, 파일 이름 또는 둘 다가 시스템에 정의된 최대 길이를 초과하는 경우

에서 지정한 sourceFileName 파일을 열 수 없거나 너무 커서 업데이트할 수 없습니다(현재 제한은 Int32.MaxValue).

sourceFileName은 디렉터리를 지정합니다.

또는

sourceFileName에서 지정한 파일에 액세스하는 데 필요한 권한이 호출자에게 없는 경우

sourceFileName에서 지정한 파일을 찾을 수 없는 경우

sourceFileName 매개 변수의 형식이 잘못되었습니다.

또는

zip 보관 위치가 쓰기를 지원하지 않는 경우

zip 보관 위치가 삭제되었습니다.

예제

다음 예제에서는 기존 파일에서 zip 보관 파일에 새 항목을 만들고 압축 수준을 지정하는 방법을 보여 있습니다.

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string zipPath = @"c:\users\exampleuser\start.zip";
            string extractPath = @"c:\users\exampleuser\extract";
            string newFile = @"c:\users\exampleuser\NewFile.txt";

            using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Update))
            {
                archive.CreateEntryFromFile(newFile, "NewEntry.txt", CompressionLevel.Fastest);
                archive.ExtractToDirectory(extractPath);
            }
        }
    }
}
Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Dim zipPath As String = "c:\users\exampleuser\end.zip"
        Dim extractPath As String = "c:\users\exampleuser\extract"
        Dim newFile As String = "c:\users\exampleuser\NewFile.txt"

        Using archive As ZipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Update)
            archive.CreateEntryFromFile(newFile, "NewEntry.txt", CompressionLevel.Fastest)
            archive.ExtractToDirectory(extractPath)
        End Using
    End Sub

End Module

설명

아카이브의 새 항목에는 로 지정된 파일의 내용이 포함됩니다 sourceFileName. 지정된 이름(entryName)이 있는 항목이 보관 파일에 이미 있는 경우 동일한 이름으로 두 번째 항목이 만들어집니다. 항목의 속성은 LastWriteTime 파일 시스템의 파일이 마지막으로 변경된 시간으로 설정됩니다.

가 있는 경우 ZipArchiveMode.Update 항목의 크기 제한은 로 Int32.MaxValue제한됩니다. 이 제한은 업데이트 모드가 내부적으로 를 MemoryStream 사용하여 보관 파일을 업데이트할 때 필요한 검색을 허용하고 MemoryStream 최대 int 크기와 같기 때문입니다.

적용 대상