Your fly down? Zip it up natively.


zipper Jaime Olivares got sick and tired of having to use the namespace or invoking shell API's to produce a Zip file.  Jaime decided to create a pure .Net 3.0 / 3.5 class that can create / append to zip file.

Here is a quick example on how he zips a file.

ZipStorer zip;

if (this.RadioCreate.Checked)
    // Creates a new zip file
    zip = ZipStorer.Create(TextStorage.Text, "Generated by ZipStorer class");
    // Creates a new zip file
    zip = ZipStorer.Open(TextStorage.Text, FileAccess.Write);

// Stores all the files into the zip file
foreach (string path in listBox1.Items)
    zip.AddFile(path, Path.GetFileName(path), "");

// Creates a memory stream with text
MemoryStream readme = new MemoryStream(
System.Text.Encoding.UTF8.GetBytes(string.Format("{0}\r\nThis file
    has been {1} using the ZipStorer class, by Jaime Olivares.",
DateTime.Now, this.RadioCreate.Checked ? "created" : "appended")));

// Stores a new file directly from the stream
zip.AddStream("readme.txt", readme, DateTime.Now, "Please read");

// Updates and closes the zip file

Another awesome thing is you can use this class with the .Net Compact Framework.



The Discussion

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.