Decompress zip file to directory - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:Zip

Description

Decompress zip file to directory

Demo Code


using System.IO.Compression;
using System.IO;//from  w ww  .  j ava 2 s  .co m
using System.Diagnostics;
using System;

public class Main{
        public static bool Decompress(string file,string toDir)
        {
            if (string.IsNullOrEmpty(file)) return false;
            if (!File.Exists(file)) return false;
            try
            {
                if (file.EndsWith(".zip"))
                {
                    DecompressZipFile(file, toDir);
                }
                else
                {
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
           
        }
        public static void DecompressZipFile(string zipFilePath, string toDir)
        {
            ZipFile.ExtractToDirectory(zipFilePath, toDir);
        }
}

Related Tutorials