How to Create Zip Archive Using C#
For creating a zip archive, we’ll use
API which is a feature-rich, powerful and easy to use API. It allows to compress & decompress ZIP, TAR, GZIP, BZ2 file formats on .NET platform without installing any software like WinRAR or 7ZIP. Moreover, developers can convert archive to another format. To add the reference, Open
package manager, search for Aspose.ZIP and install. You may also use the following command from the Package Manager Console.
PM> Install-Package Aspose.ZIP
Steps for Creating ZIP Archive in C#
Creating simple archive with
APIs can be done with just few lines of code.
- Create FileStream object with the output ZIP archive file path as parameter.
- Open and read the source file into a FileStream object with mod FileMode.Open and FileAccess.Read.
- Create Archive class object.
- use Archive.CreateEntry(string, FileStream) method to add the file into the archive.
- Use Archive.Save(FileStream) method for creating the archive.
Before executing the code below, please make sure that you have the following prerequisites on your system.
- Microsoft Windows or a compatible OS with .NET Framework, .NET Core
- Development environment like Microsoft Visual Studio
- Aspose.ZIP for .NET DLL referenced in your project
- Add namespace in relevant class file
Create ZIP Archive - C# code example
ZIP Archiving Operations
Aspose.Zip also provides some easy ways of compressing files or folders and creating ZIP archives programmatically using C#. Applications can perform tasks such as
- Store multiple files to a ZIP archive
- Store Files to Archives without compression as well
- Add folders
- Create a password protected ZIP archive using ZipCrypto
- Encrypt ZIP archive with AES encryption
- Set parallel compression mode or use LZMA, BZip2 or PPMd Compression within ZIP Archive
Online Archiving Live Demos
Compress documents right now by visiting our Live Demos website . The live demo has the following benefits