How to Unzip all .Zip file from Folder using C# 4.0 and without using any OpenSource Dll?

SHEKHAR SHETE picture SHEKHAR SHETE · Apr 17, 2013 · Viewed 75.4k times · Source

I have a folder containing .ZIP files. Now, I want to Extract the ZIP Files to specific folders using C#, but without using any external assembly or the .Net Framework 4.5.

I have searched, but not found any solution for unpacking *.zip files using Framework 4.0 or below.

I tried GZipStream, but it only supports .gz and not .zip files.

Answer

Denys Denysenko picture Denys Denysenko · Apr 17, 2013

Here is example from msdn. System.IO.Compression.ZipFile is made just for that:

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.CreateFromDirectory(startPath, zipPath);

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}

Edit: sorry, I missed that you're interests in .NET 4.0 and below. Required .NET framework 4.5 and above.