Last active
December 1, 2020 09:58
-
-
Save aspose-com-gists/5035e16331e147a3dc2b2261dc14d167 to your computer and use it in GitHub Desktop.
Unzip/extract files in ZIP using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open ZIP file | |
using (FileStream zipFile = File.Open("encrypted.zip", FileMode.Open)) | |
{ | |
// Decrypt and extract to folder | |
new Archive(zipFile, new ArchiveLoadOptions() { DecryptionPassword = "p@s$" }).ExtractToDirectory("decrypted"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open ZIP file | |
using (FileStream zipFile = File.Open("compressed_files.zip", FileMode.Open)) | |
{ | |
using (Archive archive = new Archive(zipFile, new ArchiveLoadOptions())) | |
{ | |
// Access each entry in ZIP archive | |
for (int i = 0; i < archive.Entries.Count; i++) | |
{ | |
int percentReady = 0; | |
// Log extraction progress to the console. | |
archive.Entries[i].ExtractionProgressed += (s, e) => | |
{ | |
int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize); | |
if (percent > percentReady) | |
{ | |
Console.WriteLine(string.Format("{0}% decompressed", percent)); | |
percentReady = percent; | |
} | |
}; | |
// Extract entry's content to disk. | |
archive.Entries[i].Extract(archive.Entries[i].Name); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open ZIP file | |
using (FileStream zipFile = File.Open("compressed_files.zip", FileMode.Open)) | |
{ | |
using (var archive = new Archive(zipFile)) | |
{ | |
// Unzip files to folder | |
archive.ExtractToDirectory("Unzipped Files"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open ZIP file | |
using (FileStream zipFile = File.Open("compressed_files.zip", FileMode.Open)) | |
{ | |
// Decrypt using password | |
using (var archive = new Archive(zipFile, new ArchiveLoadOptions() { DecryptionPassword = "p@s$" })) | |
{ | |
// Extract files to folder | |
archive.ExtractToDirectory("Unzipped Files"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment