
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

Oct 05, 2026 - 12 min read
Problem Details in ASP.NET Core and .NET 11
builder.Services.AddProblemDetails() registers infrastructure. It does not create an error contract. An ASP.NET Core request can fail during …

Sep 21, 2026 - 11 min read
Resilience in .NET with Microsoft.Extensions.Resilience
Retries are the most visible resilience strategy and the easiest one to misuse. Repeating a failing call can recover from a short network …

Sep 14, 2026 - 10 min read
What Matters in ASP.NET Core 11
ASP.NET Core 11 has no single feature that fundamentally changes how web applications are built. That is not a criticism. Mature frameworks …
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.
