Created
November 26, 2015 21:42
-
-
Save shammelburg/6d76c5db2249218fb3a8 to your computer and use it in GitHub Desktop.
Ionic Zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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