使用ICSharpCode.SharpZipLib.Zip类库解压zip文件的方法

public static bool ZipExtractFile(string zipFilePath,string targetPath)
        {
            FastZip fastZip = new FastZip();
            try
            {
                if (!Directory.Exists(targetPath))
                    Directory.CreateDirectory(targetPath);

                DirectoryInfo DirInfo = new DirectoryInfo(targetPath);
                       DirInfo.Attributes = FileAttributes.Normal & FileAttributes.Directory;



                fastZip.ExtractZip(zipFilePath, targetPath, "xls");
                return true;
            }
            catch
            {
                return false;
            }

        }
//这个方法不支持解压rar格式的文件,因为rar格式的文件是商业公司定义的,正版的winrar的软件也是收费的. 
用此方法解压rar格式的文件,会提示错误:"cann't find central directory"
//大家在使用的时候,请注意这一点 如下图所示:
 

原文地址:https://www.cnblogs.com/kdkler/p/6066809.html