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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more