public static void ZipFiles(string InputFolderPath, string outputPathAndFile, string password)
{
string outPath = outputPathAndFile;
ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath));
int TrimLength = 0;
if (Directory.GetParent(InputFolderPath) != null)
{
TrimLength = (Directory.GetParent(InputFolderPath)).ToString().Length;
TrimLength += 1; //remove '\'
}
string DirPath = outPath.Remove(outPath.LastIndexOf(@"\"));
if (!Directory.Exists(DirPath))
Directory.CreateDirectory(DirPath);
DirectoryInfo dinf = new DirectoryInfo(InputFolderPath);
if (dinf.Exists)
{
if (!string.IsNullOrEmpty(password))
oZipStream.Password = password;
oZipStream.SetLevel(9); // maximum compression
ArrayList ar = GenerateFileList(InputFolderPath); // generate file list
foreach (object t in ar)
{
string Fil = t.ToString();
ZipFile(TrimLength, oZipStream, Fil);
}
}
else
{
FileInfo finf = new FileInfo(InputFolderPath);
if (!string.IsNullOrEmpty(password))
oZipStream.Password = password;
oZipStream.SetLevel(9); // maximum compression
ZipFile(TrimLength, oZipStream, finf.FullName);
}
oZipStream.Finish();
oZipStream.Close();
}