/// <summary> /// Unzip a file and any zip files contained within it. /// </summary> /// <param name="zipFile">path of zipfile</param> /// <returns>true if file successfully unzipped, false if it failed</returns> private bool UnzipFile(string zipFile) { try { //Unzip the zip file string zipFileName = Path.GetFileName(zipFile); //DV NT Re-eng Phase 1 set as a public for use elsewhere _zipFileName = zipFileName; // create a public guid for the big zip file - not working as this is called for each little zip _guid = Guid.NewGuid().ToString(); string zipFilePath = zipFile.Replace(zipFileName, ""); string zipFileSubDir = zipFilePath + zipFileName.Substring(0, zipFileName.Length - 4); Directory.CreateDirectory(zipFileSubDir); QuickZip.Unzip(zipFile, zipFileSubDir, new string[] { "*" }); //Scan the unipped contents for input files ScanForInputFiles(zipFileSubDir); //DirectoryInfo dirInfo = new DirectoryInfo(zipFileSubDir); //dirInfo.Delete(true); } catch (Exception e) { NexdoxMessaging.SendMessage("Failed to unzip file: " + zipFile + " error message: " + e.Message, true, this); //_errorFiles.Add(); return(false); } return(true); }
/// <summary> /// This private method uses XCeed library to decompress the folder or file /// </summary> /// <param name="compressedFile">Name of the file to be decompressed</param> /// <param name="destinationPath">Path where ExtractToFolder will be created</param> /// <param name="extractToFolder">ExtractToFolder contains all the decompressed files</param> /// <param name="emailInterchangeId">Email Interchange ID</param> /// <param name="requestType">Request Type</param> /// <param name="isItAFolder">It indicate whether to decompress a folder or a file, since we made this as Optional parameter by default it will takes true</param> /// <param name="canDeleteCompressedfile">It indicate whether to delete the compressed folder after the decompression or not, if true it will delete the compressed fodler</param> /// <returns></returns> public bool DecompressFileOrFolder(string compressedFile, string destinationPath, string extractToFolder, string xceedLicenseKey, bool isItAFolder = true, bool canDeleteCompressedfile = false) { if (string.IsNullOrWhiteSpace(compressedFile)) { throw new ArgumentNullException("compressedFile"); } Xceed.Zip.Licenser.LicenseKey = xceedLicenseKey; try { if (isItAFolder) { if (string.IsNullOrWhiteSpace(destinationPath)) { throw new ArgumentNullException("destinationPath"); } if (string.IsNullOrWhiteSpace(extractToFolder)) { throw new ArgumentNullException("extractToFolder"); } destinationPath = Path.Combine(destinationPath, extractToFolder); if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } QuickZip.Unzip(compressedFile, destinationPath, "*"); } else { var compressedFileInfo = new FileInfo(compressedFile); QuickZip.Unzip(compressedFile, compressedFileInfo.Directory.FullName, "*"); } if (canDeleteCompressedfile && File.Exists(compressedFile)) { System.IO.File.Delete(compressedFile); } return(true); } catch (Exception ex) { throw ex; } }
protected string ExtractContents(FileInfo fileInfo) { var freeDiskSpace = fileInfo.Directory.Root.Name.GetFreeDiskSpace(); if (3.0 * fileInfo.Length > freeDiskSpace) { throw new ApplicationException(string.Format(@"--- The current free disk space <{0}> of drive <{1}> is not enough to extracting the contents!", freeDiskSpace, fileInfo.Directory.Root)); } var extractedFolder = Path.Combine(_extractingResultsDir, fileInfo.MD5().ToString()); CreateSubfolder(extractedFolder, fileInfo.Name); fileInfo.FullName.RemoveFileReadOnlyAttribute(); QuickZip.Unzip(fileInfo.FullName, extractedFolder, _password, true, true, true, "*"); //File.Delete(fileInfo.FullName); return(extractedFolder); }
public void ExtractArchiveTo(string distinationFolder, string password = null) { QuickZip.Unzip(_sourceArchiveFile, distinationFolder, password, true, true, true, "*"); }