DEV Community

Frederik Van Lierde
Frederik Van Lierde

Posted on

How to Zip a directory with dotNet

Ever seen an online platform allowing you to back up your work and let you download a Zip file? Shouldn't all platforms offer this ;)

The good news is that the dotNet framework offers this feature standard with the System.IO.Compression.ZipFile static class.

The class allows you to create, extract, and open zip archives.

This feature is available for a long time, from .NETCore 1.0, .Net Framework 4.5, .NET Standard 1.3, but I don't see it used that often. That's why I made this article and we are implementing this feature on our Web Stories Today platform.

Pre-Requisites

To use the ZipFile class in a .NET Framework app, you must add a reference to the System.IO.Compression.FileSystem assembly in your project.

Zip a directory

ZipFile.CreateFromDirectory(directoryToZip, resultZipFilePath);
Enter fullscreen mode Exit fullscreen mode

Extract to a directory

ZipFile.ExtractToDirectory(ZipFilePath, extractPath);
Enter fullscreen mode Exit fullscreen mode

Conclusion

It is s easy, no platform has an excuse not to offer a Zipped backup of your content and work

Top comments (0)