
Working with compressed files is common in many applications, whether you’re extracting data from an archive, installing software packages or retrieving bundled files. Thankfully, .NET finally provides an efficient, straightforward way to decompress ZIP files using the System.IO.Compression namespace. In this post, I’ll walk through a simple code snippet that you can use to decompress ZIP files in your .NET apps.
1namespace BenjaminAbt.ZipFileSample;
2
3using System;
4using System.IO;
5using System.IO.Compression;
6
7class Program
8{
9 static void Main()
10 {
11 // fullname zip file
12 string zipFilePath = @"C:\ben\path\to\your\compressedFolder.zip";
13
14 // target folder to write files of the zip archive
15 string extractPath = @"C:\ben\path\to\extract\folder";
16
17 DecompressZipFile(zipFilePath, extractPath);
18 Console.WriteLine("ZIP file decompressed successfully!");
19 }
20
21 static void DecompressZipFile(string zipFilePath, string extractPath)
22 {
23 if (Directory.Exists(extractPath))
24 {
25 Directory.Delete(extractPath, recursive: true); // Delete existing directory to avoid conflicts
26 }
27
28 ZipFile.ExtractToDirectory(zipFilePath, extractPath);
29 }
30}
How It Works
- Set File Paths: Define zipFilePath as the path to the ZIP file you want to decompress and
extractPathas the folder where you want the files extracted. - Handle Existing Directories: The snippet checks if a folder already exists at
extractPath. If it does, it deletes it to prevent conflicts during decompression. - Decompress with
ZipFile.ExtractToDirectory: The ExtractToDirectory method handles the decompression, extracting the contents of the ZIP file to the specified destination.
Related articles

Dec 05, 2025 · 5 min read
IMemoryCache Entry Invalidation (Manual Cache Busting)
IMemoryCache is great for speeding up expensive operations (database reads, HTTP calls, heavy computations). But many real systems need more …

Nov 08, 2025 · 8 min read
.NET 10 Release: What's New (LTS) and What to Upgrade First
.NET 10 is the next Long-Term Support (LTS) release in the .NET family. LTS matters because it’s the version many teams standardize on …

Sep 24, 2025 · 9 min read
Automatically discover tools for Azure OpenAI Realtime API
Azure now provides a unified Realtime API for low‑latency, multimodal conversations over WebRTC or WebSockets. If you’ve used the earlier …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

Comments