In the 7-Zip app, navigate to the folder with the ZIP file and the other files. Select the files, and click the Add button at the top. In the window that opens set the Archive format to ZIP, and in the Update mode, select ‘Update and add files’. Click Ok, and the files will be added to the zipped file. To zip one or more files or folders in Windows 10, the first step is to open up File Explorer. From there, all you have to do is select your files and use either the Send To menu or the Ribbon. You can upload the zip file either through the website, desktop app or mobile app. If you're using a computer, you can check out the steps listed here to upload either via the website or the desktop app. Please bear in mind that the file will need to be 50 GB or smaller to be uploaded via the website, while there isn't a limit for the desktop app.
The ZIP archives are used to compress and keep one or more files or folders into a single container. A ZIP archive encapsulates the files and folders as well as holds their metadata information. The most common usage of archiving is reducing the size of the files for storage or transmission and applying encryption for security. Apart from the file compression tools, the automated compression/extraction features are also used within various desktop and web applications for uploading, downloading, sharing, or encrypting the files. This article also targets similar scenarios and presents some easy ways of compressing files or folders and creating ZIP archivesprogrammatically using C#.
In this article, you will learn how to perform the following ZIP archiving operations:
Prerequisite – C# ZIP Library
Aspose.ZIP for .NET is a powerful and easy to use API for zipping or unzipping files and folders within .NET applications. It also provides AES encryption techniques to encrypt the files in ZIP archives. You can install the API from NuGet or download its binaries from the Downloads section.
Create a ZIP Archive in C#
The following are the steps to compress a file by adding it into a ZIP archive:
- Create a FileStream object for the output ZIP archive.
- Open the source file into a FileStream object.
- Create an object of Archive class.
- Add the file into the archive using Archive.CreateEntry(string, FileStream) method.
- Create the ZIP archive using Archive.Save(FileStream) method.
The following code sample shows how to add a file into a ZIP archive using C#.
View the code on Gist.
Add Multiple Files into ZIP Archive in C#
In case you want to add multiple files into a ZIP archive, you can do it using one of the following ways.
ZIP Multiple Files using FileStream
In this method, the FileStream class is used to add files to the ZIP archive using Archive.CreateEntry(String, FileStream) method. The following code sample shows how to add multiple files into a ZIP in C#.
View the code on Gist.
ZIP Multiple Files using FileInfo
You can also use the FileInfo class for adding multiple files into a ZIP archive. In this method, the files will be loaded using the FileInfo class and added to the ZIP archive using Archive.CreateEntry(String, FileInfo) method. The following code sample shows how to ZIP multiple files using the FileInfo class in C#.
View the code on Gist.
ZIP Files using Path
Instead of using FileInfo or FileStream classes for the ZIP entries, you can provide the file’s path directly to Archive.CreateEntry(String name, String path, Boolean openImmediately, ArchiveEntrySettings newEntrySettings) method. The following code sample shows how to ZIP files using their path.
View the code on Gist.
Add Folders to a ZIP Archive in C#
You can ZIP a folder as well which could be another alternative of adding multiple files to a ZIP archive. Just put the source files into a folder and add that folder to the ZIP archive. The following are the steps to ZIP a folder:
- Create an object of FileStream class for the output ZIP archive.
- Create an instance of the Archive class.
- Use the DirectoryInfo class to specify the folder to be zipped.
- Use Archive.CreateEntries(DirectoryInfo) method to add folder into ZIP.
- Create the ZIP archive using Archive.Save(FileStream) method.
The following code sample shows how to add a folder to ZIP in C#.
View the code on Gist.
Create a Password-Protected ZIP Archive using ZipCrypto in C#
You can protect the ZIP archives using passwords and apply ZipCrypto encryption. For this, the ArchiveEntrySettings class is used in the constructor of the Archive that accepts the encryption type as the second parameter.
The following code sample shows how to create a password-protected ZIP archive using ZipCrypto in C#.
View the code on Gist.
Create AES Encrypted ZIP Archives in C#
Aspose.ZIP for .NET also lets you apply AES encryption to the ZIP archives. You can use the following AES encryption methods:
- AES128
- AES192
- AES256
Software data cable exe. In order to apply AES encryption, API offers the AesEcryptionSettings class. The following code sample shows how to create an AES encrypted ZIP archive in C#.
View the code on Gist.
Set Parallel Compression Mode
You can also configure the API for parallel compression in case of multiple entries. For this, you can specify the parallel compression mode using ParallelOptions class. Aspose.ZIP for .NET provides the following parallel compression modes.
- Never – Do not compress in parallel.
- Always – Do compress in parallel (beware out of memory).
- Auto – Decide whether to use parallel compression or not upon the entries. This option may compress some entries in parallel only.
The following code sample shows how to set parallel compression mode while zipping multiple files.
View the code on Gist.
Learn more about Aspose.ZIP for .NET
How Do I Put Files Into A Zip File Opener
Explore more about our C# ZIP API using the following resources: