/// <Summary> /// function: Decompress a zip file. /// </Summary> /// <param name = "zipFilePath"> compressed file path </param> /// <param name = "unZipDir"> decompressed file storage path, if it is null, it is in the same directory as the compressed file by default, folder with the same name as the compressed file </param> /// <param name = "err"> error message </param> /// <returns> whether the decompression is successful </returns> public bool UnZipFile (string zipFilePath, string unZipDir) //, out string err {// err = ""; if (zipFilePath = string. empty) {// err = "the compressed file cannot be blank! "; Return false;} if (! File. Exists (zipFilePath) {// err = "the compressed File does not exist! "; Return false;} // if (unZipDir = string. empty) unZipDir = zipFilePath. replace (Path. getFileName (zipFilePath), Path. getFileNameWithoutExtension (zipFilePath); if (! UnZipDir. EndsWith ("\") unZipDir + = "\"; if (! Directory. exists (unZipDir) Directory. createDirectory (unZipDir); try {using (ZipInputStream s = new ZipInputStream (File. openRead (zipFilePath. toLower () {ZipEntry theEntry; while (theEntry = s. getNextEntry ())! = Null) {string directoryName = Path. getDirectoryName (theEntry. name); string fileName = Path. getFileName (theEntry. name); if (directoryName. length> 0) {Directory. createDirectory (unZipDir + directoryName);} if (! DirectoryName. EndsWith ("\") directoryName + = "\"; if (fileName! = String. empty) {using (FileStream streamWriter = File. create (unZipDir + theEntry. name) {int size = 2048; byte [] data = new byte [2048]; while (true) {size = s. read (data, 0, data. length); if (size> 0) {streamWriter. write (data, 0, size) ;}else {break ;}}}// while} catch (Exception ex) {// err = ex. message; return false;} return true;} // decompress