Your fly down? Zip it up natively.
Jaime Olivares got sick and tired of having to use the java.util.zip 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");
else
// 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");
readme.Close();
// Updates and closes the zip file
zip.Close();
Another awesome thing is you can use this class with the .Net Compact Framework.
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using