ICSharpCode.SharpZipLib.dll
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
public static void ZipFolder(string zipFileName,string zipFolder)
{try
{
string zipFilePath = zipFileName + ".zip";
string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string keyLogPath = Path.Combine(AppPath, zipFolder);
string temp = Path.Combine(keyLogPath, "Translation");
string[] fileNames = Directory.GetFileSystemEntries(keyLogPath);
// Zip up the files - From SharpZipLib Demo Code
using (ZipOutputStream s = new
ZipOutputStream(File.Create(zipFilePath)))
{
s.SetLevel(4); // 0-9, 9 being the highest compression
byte[] buffer = new byte[4096];
foreach (string file in fileNames)
{
if (file.Substring(file.Length-3) == "txt")
{
ZipEntry entry = new
ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0,
buffer.Length);
s.Write(buffer, 0, sourceBytes);
}
while (sourceBytes > 0);
}
}
}
s.Finish();
s.Close();
}
//if (File.Exists(zipFilePath))
// Utilities.Paths.SyncReportZipPath = zipFilePath;
}
catch (IOException ioex)
{
bool rethrow =
ExceptionPolicy.HandleException(ioex, "BFPolicy");
if (rethrow)
throw;
return;
}
catch (Exception ex)
{
bool rethrow =
ExceptionPolicy.HandleException(ex, "BFPolicy");
if (rethrow)
throw;
return;
}
}