Exemplo n.º 1
0
        /// <summary>
        /// Extracts all the files in the specified zip archive to a directory on the file system and uses the specified character encoding for entry names, and IProgress.
        /// </summary>
        /// <param name="sourceArchiveFileName">The path to the archive that is to be extracted.</param>
        /// <param name="destinationDirectoryName">The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.</param>
        /// <param name="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.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static async Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, Encoding entryNameEncoding, IProgress <ZipArchiveEntryProgressInfo> progress)
        {
            if (!File.Exists(sourceArchiveFileName))
            {
                throw new FileNotFoundException(string.Format("{0} does not exist.", sourceArchiveFileName));
            }

            if (!Directory.Exists(destinationDirectoryName))
            {
                throw new DirectoryNotFoundException(string.Format("{0} does not exist.", destinationDirectoryName));
            }

            using (var zip = new ZipArchive(File.OpenRead(sourceArchiveFileName), ZipArchiveMode.Read, false, entryNameEncoding))
            {
                await zip.ExtractToDirectoryAsync(destinationDirectoryName, progress);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Extracts all the files in the zip archive to a directory on the file system.
 /// </summary>
 /// <param name="zip">The zip archive to extract files from.</param>
 /// <param name="destinationDirectoryName">The path to the directory to place the extracted files in. You can specify either a relative or an absolute path. A relative path is interpreted as relative to the current working directory.</param>
 /// <returns>The task object representing the asynchronous operation.</returns>
 public static async Task ExtractToDirectoryAsync(this ZipArchive zip, string destinationDirectoryName)
 {
     await zip.ExtractToDirectoryAsync(destinationDirectoryName, null);
 }