Unzip a Zip File in C#

This tutorial will discuss the method to unzip a file in C#.

Unzip a File With the ZipFile.ExtractToDirectory() Function in C

The ZipFile class is used to create, open and extract zip files in C#. The Zipfile.ExtractToDirectory() method extracts a zip file from a specified source folder to a destination folder. We need first to install the package System.IO.Compression to use this method. The file extension needs to be .zip for this method to work properly.

using System;
using System.IO.Compression;

namespace unzip_file
    class Program
        static void Main(string[] args)
            string zipFilePath = @"C:\File\milestone 19.zip";
            string extractionPath = @"C:\File";
            ZipFile.ExtractToDirectory(zipFilePath, extractionPath);
            Console.WriteLine("Extracted Successfully");


Extracted Successfully

In the above code, we extracted the zip file milestone 19.zip inside the path C:\File to the path C:\File with the ZipFile.ExtractToDirectory() function in C#.

DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Csharp File

  • Read a File to String in C#