public static bool ZipDirectory(string inputDirectpath, string outZipFilePath)
{
try
{
Crc32 crc = new Crc32();
FileStream fs1 = File.Create(outZipPath);
ZipOutputStream s = new ZipOutputStream(fs1);
s.SetLevel(6); // 0 - store only to 9 - means best compression
DirectoryInfo di = new DirectoryInfo(inputpath);
foreach (FileInfo file in di.GetFiles())
{
FileStream fs = file.OpenRead();
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string filename = file.Name;
ZipEntry entry = new ZipEntry(filename);
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
return true;
}
catch(System.Exception ex)
{
string a = ex.Message;
return false;
}
}