DEV Community

Frederik Van Lierde
Frederik Van Lierde

Posted on

2

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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay