/// <summary> /// This method decompresses a file /// </summary> /// <param name="sourceFolderOrFile">File or folder to be decompressed</param> /// <param name="destinationCompressFile">Resultant file or folder to created after decompression</param> /// <param name="isItAFolder">Used as <c>isItAFolder?</c> flag</param> /// <param name="xceedLicenseKey">License Key for Xceed Library</param> /// <returns>Returns if file or decompression was successful or not</returns> public bool CompressFileOrFolder(string sourceFolderOrFile, string destinationCompressFile, bool isItAFolder, string xceedLicenseKey) { if (string.IsNullOrWhiteSpace(sourceFolderOrFile)) { throw new ArgumentNullException("sourceFolderOrFile"); } if (string.IsNullOrWhiteSpace(destinationCompressFile)) { throw new ArgumentNullException("destinationCompressFile"); } Licenser.LicenseKey = xceedLicenseKey; try { if (isItAFolder) { QuickZip.Zip(destinationCompressFile, false, false, false, Directory.EnumerateFiles(sourceFolderOrFile).ToArray()); } else { QuickZip.Zip(destinationCompressFile, false, false, false, sourceFolderOrFile); } return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// This private method uses XCeed library to compress the folder or file /// </summary> /// <param name="sourceFolderOrFile">Folder or file to be compressed</param> /// <param name="destinationCompressFile">Name of the resultant compressed file</param> /// <param name="blnCompressFolder">It indicate whether to compress a folder or a file</param> /// <returns></returns> private static bool DoCompress(string sourceFolderOrFile, string destinationCompressFile, bool blnCompressFolder, string XceedLicenseKey) { if (string.IsNullOrWhiteSpace(sourceFolderOrFile)) { throw new ArgumentNullException("sourceFolderOrFile"); } if (string.IsNullOrWhiteSpace(destinationCompressFile)) { throw new ArgumentNullException("destinationCompressFile"); } Xceed.Zip.Licenser.LicenseKey = XceedLicenseKey; try { if (blnCompressFolder) { QuickZip.Zip(destinationCompressFile, false, false, false, Directory.EnumerateFiles(sourceFolderOrFile).ToArray()); } else { QuickZip.Zip(destinationCompressFile, false, false, false, sourceFolderOrFile); } return(true); } catch { throw; } }
public static void ZipDownloadHandler(IHttpContext context) { var path = new BackSlashPath(ExamplesConfiguration.UnprotectString(context.Request["path"])).RemoveTrailingSlash(); var fileResponse = new FileResponse(context, 0); fileResponse.Transmit((targetStream) => { QuickZip.Zip(targetStream, Directory.EnumerateFileSystemEntries(path)); }, path.FileName + ".zip", 0); }
public void Zip(string zipFile, string[] files) { QuickZip.Zip(zipFile, true, true, false, files); }