How can I Compress a directory with .NET?

Look into using SharpZipLib. It supports both GZip and ZIP compression in C#.

There is an excellent tutorial here outlining what you need to do to zip a directory with SharpZipLib.


You can use DotNetZip Library. It has quite rich and useful features.


EDIT:

string[] MainDirs = Directory.GetDirectories(DirString);

for (int i = 0; i < MainDirs.Length; i++)
{
    using (ZipFile zip = new ZipFile())
    {
        zip.UseUnicodeAsNecessary = true;
        zip.AddDirectory(MainDirs[i]);
        zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
        zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
        zip.Save(string.Format("test{0}.zip", i));   
    }
}

use 7zip from commandline in C# --> LZMA SDK supports C#, and there are codesamples in the package