⌘BABAKOV.NET Let's code!
100% [dark] [ru]

Creating Zip Archives in C#

The easiest way to create archives in C# is to use the special library 'DotNetZip'. The library has a very large functionality and allows you to do real wonders, but at the same time it is very simple to use when you need to quickly pack or unpack something small. Moreover, the package even includes a library for the Compact Framework.

A simple example of code for creating an archive using the library:

ZipFile zf = new ZipFile("файл архива");
zf.AddDirectory("Папка на диске которую хотим поместить в архив со всем содержимым");
zf.Save(); //Сохраняем архив.


You will, of course, need to connect the library first:

using Ionic.Zip;



A simple example for extracting files from the archive:

if (ZipFile.IsZipFile(openFileDialog1.FileName))//Проверка - действительно ли это Архив.
{
     ZipFile zf = new ZipFile("Файл архива.zip");
     zf.ExtractAll("Путь куда распаковать файлы");
}



That's it.

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.