How to 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");
}
}
}
Output:
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#.
Maisam is a highly skilled and motivated Data Scientist. He has over 4 years of experience with Python programming language. He loves solving complex problems and sharing his results on the internet.
LinkedIn