February 16, 2010


Quick way to include Zip file functionality.
Find up to date version at http://zipstorer.codeplex.com/
The nice thing about ZipStorer is that you dont need to reference any other assemblies, you just include the class file in your project and away you go.
Quick and dirty example of using ZipStorer to compress a bunch of files:
saveFilePath = System.IO.Path.ChangeExtension(saveFilePath, "zip");
StringBuilder fileList = new StringBuilder();
string comment = "File changes from: " + 
                 DateTime.UtcNow.ToLongDateString() +
                 Environment.NewLine +
                 "Original path: " + rootDir;                                  
using (ZipStorer zipStore = ZipStorer.Create(saveFilePath, comment))
    foreach (CheckedListItem cli in listBoxFilesChanged.SelectedItems)
        if (cli.FileSystemInfo.Exists)
            zipStore.AddFile(ZipStorer.Compression.Deflate, // Compress
               cli.FullName,     // Full path of file to be added
               cli.RelativeName, // Stored as a relative path in zip file
               cli.FullName);    // Comment for stored file (source of the original)

No comments: