Last active
October 7, 2022 15:16
-
-
Save aspose-com-gists/dea0000f742629e43ecc24f5a19ab2ac to your computer and use it in GitHub Desktop.
Create ZIP Archives in 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
// Create FileStream for output ZIP archive | |
using (FileStream zipFile = File.Open("archive.zip", FileMode.Create)) | |
{ | |
// Create archive | |
using (var archive = new Archive()) | |
{ | |
// Add file to ZIP archive | |
archive.CreateEntry("data.bin", "file.dat"); | |
archive.Save(zipFile); | |
} | |
} |
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
// Create FileStream for output ZIP archive | |
using (FileStream zipFile = File.Open("compressed_files.zip", FileMode.Create)) | |
{ | |
// Files to be added to archive | |
FileInfo fi1 = new FileInfo("alice29.txt"); | |
FileInfo fi2 = new FileInfo("fields.c"); | |
using (var archive = new Archive()) | |
{ | |
// Add files to the archive | |
archive.CreateEntry("alice29.txt", fi1); | |
archive.CreateEntry("fields.c", fi2); | |
// Create ZIP archive | |
archive.Save(zipFile, new ArchiveSaveOptions() { Encoding = Encoding.ASCII }); | |
} | |
} |
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
// Create FileStream for output ZIP archive | |
using (FileStream zipFile = File.Open("compressed_files.zip", FileMode.Create)) | |
{ | |
// File to be added to archive | |
using (FileStream source1 = File.Open("alice29.txt", FileMode.Open, FileAccess.Read)) | |
{ | |
// File to be added to archive | |
using (FileStream source2 = File.Open("asyoulike.txt", FileMode.Open, FileAccess.Read)) | |
{ | |
using (var archive = new Archive()) | |
{ | |
// Add files to the archive | |
archive.CreateEntry("alice29.txt", source1); | |
archive.CreateEntry("asyoulik3.txt", source2); | |
// ZIP the files | |
archive.Save(zipFile, new ArchiveSaveOptions() { Encoding = Encoding.ASCII, ArchiveComment = "two files are compressed in this archive" }); | |
} | |
} | |
} | |
} |
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
// Create FileStream for output ZIP archive | |
using (FileStream zipFile = File.Open("compress_directory.zip", FileMode.Create)) | |
{ | |
using (Archive archive = new Archive()) | |
{ | |
// Folder to be Zipped | |
DirectoryInfo corpus = new DirectoryInfo("CanterburyCorpus"); | |
archive.CreateEntries(corpus); | |
// Create ZIP archive | |
archive.Save(zipFile); | |
} | |
} |
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
// Create FileStream for output ZIP archive | |
using (FileStream zipFile = File.Open("compress_directory.zip", FileMode.Create)) | |
{ | |
using (Archive archive = new Archive(new ArchiveEntrySettings(null, new TraditionalEncryptionSettings("p@s$")))) | |
{ | |
// Add folder to the archive | |
DirectoryInfo corpus = new DirectoryInfo("CanterburyCorpus"); | |
archive.CreateEntries(corpus); | |
// Create ZIP archive | |
archive.Save(zipFile); | |
} | |
} |
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
// Create FileStream for output ZIP archive | |
using (FileStream zipFile = File.Open("compressed_file.zip", FileMode.Create)) | |
{ | |
// File to be added to archive | |
using (FileStream source1 = File.Open("alice29.txt", FileMode.Open, FileAccess.Read)) | |
{ | |
using (var archive = new Archive(new ArchiveEntrySettings())) | |
{ | |
// Add file to the archive | |
archive.CreateEntry("alice29.txt", source1); | |
// ZIP file | |
archive.Save(zipFile); | |
} | |
} | |
} |
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
// Create FileStream for output ZIP archive | |
using (FileStream zipFile = File.Open("compress_directory.zip", FileMode.Create)) | |
{ | |
using (Archive archive = new Archive(new ArchiveEntrySettings(null, new AesEcryptionSettings("p@s$", EncryptionMethod.AES128)))) | |
{ | |
// Add folder to archive | |
DirectoryInfo corpus = new DirectoryInfo("CanterburyCorpus"); | |
archive.CreateEntries(corpus); | |
// Create ZIP archive | |
archive.Save(zipFile); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment