Skip to content

Instantly share code, notes, and snippets.

@shammelburg
Created November 26, 2015 21:42
Show Gist options
  • Save shammelburg/6d76c5db2249218fb3a8 to your computer and use it in GitHub Desktop.
Save shammelburg/6d76c5db2249218fb3a8 to your computer and use it in GitHub Desktop.
Ionic Zip
using Ionic.Zip;
[HttpPost]
public void ZipFiles(FormCollection collection)
{
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
var file_collection = _repository.GetListOfFiles();
foreach (var file in file_collection)
{
// location , folder name
zip.AddFile(file.FileLocation, file.Name);
}
Response.Clear();
Response.BufferOutput = false;
//sets the zip folder name with date and time
string zipName = String.Format("FolderName_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
Response.End();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment