C# ZipFile Open(String, ZipArchiveMode, Encoding)
Description
ZipFile Open(String, ZipArchiveMode, Encoding)
Opens
a zip archive at the specified path, in the specified mode, and by using the
specified character encoding for entry names.
Syntax
ZipFile.Open(String, ZipArchiveMode, Encoding)
has the following syntax.
public static ZipArchive Open(
string archiveFileName,//from w ww . j a v a 2 s. co m
ZipArchiveMode mode,
Encoding entryNameEncoding
)
Parameters
ZipFile.Open(String, ZipArchiveMode, Encoding)
has the following parameters.
archiveFileName
- The path to the archive to open, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.mode
- One of the enumeration values that specifies the actions that are allowed on the entries in the opened archive.entryNameEncoding
- The encoding to use when reading or writing entry names in this archive. Specify a value for this parameter only when an encoding is required for interoperability with zip archive tools and libraries that do not support UTF-8 encoding for entry names.
Returns
ZipFile.Open(String, ZipArchiveMode, Encoding)
method returns The opened zip archive.
Example
using System;/*w w w . ja v a 2 s .com*/
using System.IO;
using System.IO.Compression;
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);
}
}
}