Guest User

Guest User

  • Tech Writer
  • 140
  • 1k

Create Zip Using ionic

Mar 28 2018 3:23 AM
public static void CreateZipForCronjob(string PathForTheFilesToBeIncludedInZip, string PathForTheZip, string ZipName, DateTime Date, bool IsDateFilter = false)
{
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
var FileNamesList = Directory.GetFiles(HttpContext.Current.Server.MapPath(PathForTheFilesToBeIncludedInZip), "*.pdf").ToList();
for (int i = 0; i < FileNamesList.Count; i++)
{
string filePath = FileNamesList[i];

if (IsDateFilter)
{
if (filePath.ToString().Contains(Date.ToString("dd-MMM-yyyy")))
{
zip.AddFile(filePath, ZipName);
}
}
else
{
zip.AddFile(filePath, ZipName);
}
}
zip.Save(HttpContext.Current.Server.MapPath(PathForTheZip) + ZipName);
for (int i = 0; i < FileNamesList.Count; i++)
{
string filePath = FileNamesList[i];
File.Delete(filePath);
}
}
}

Answers (1)