(Sharpziplib.dll) http://www.icsharpcode.net/
///
Using system; using system.io;
Using ICSHARPCODE.SHARPZIPLIB.CHECKSUMS; Using ICSHARPCODE.SHARPZIPLIB.ZIP; Using ICSHARPCODE.SHARPZIPLIB.GZIP;
namespace Compression {public class ZipClass {public void ZipFile (string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize) {// If the file is not found, then an error if (! System.IO.File.Exists (FileToZip)) {throw new System.IO.FileNotFoundException ( "The specified file" FileToZip "could not be found Zipping aborderd.");} System.IO.FileStream StreamToZip = new System.IO.FileStream (FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.FileStream ZipFile = System.IO.File.Create (ZipedFile); ZipOutputStream ZipStream = new ZipOutputStream (ZipFile); ZipEntry ZipEntry = new ZipEntry ( "ZippedFile"); ZipStream.PutNextEntry (ZipEntry); ZipStream.SetLevel (CompressionLevel); byte [] buffer = new byte [BlockSize]; System.Int32 size = StreamToZip.Read (buffer, 0, buffer.Length); ZipStream.Write (buffer, 0, size) ; {While (size Entry.datetime = datetime.now; // set size and the crc, because the information // About the size and crc shop be stored in the header // if it is not set it is automaticly write in the footer. // ( In this case size == crc == -1 in the header) // Some Zip Programs Have Problems with zip files That don't store // The size and crc in the header. entry.size = fs.length; fs. Close (); crc.reset (); crc.Update (buffer); entry.crc = crc.value; s.putnextentry; s.write (buffer, 0, buffer.length);} S.Finish ); S.close ();}}} Now let's take a look at the source code of the decompressed file class /// Using system.collection; using system.io; using system.diagnostics; using system.runtime.serialization.formatters.binary; using system.data ;. using system.data ;. USING SYSTEM. using ICSharpCode.SharpZipLib.BZip2; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Zip.Compression; using ICSharpCode.SharpZipLib.Zip.Compression.Streams; using ICSharpCode.SharpZipLib.GZip; namespace DeCompression {public class UnZipClass {public void UnZip (string [] args) {ZipInputStream s = new ZipInputStream (File.OpenRead (args [0])); ZipEntry theEntry;! while ((theEntry = s.GetNextEntry ()) = null) {string directoryName = Path.GetDirectoryName (args [1]); string fileName = Path.GetFileName (theEntry.Name); // create decompressed directory Directory.CreateDirectory (directoryName);! if (fileName = String.Empty) { // Unzip file to the specified directory fileStream StreamWriter = file.create (args [1] thentry.name); int size = 2048; Byte [] data = new byte [2048]; while (true) {size = s. Read (Data, 0, Data.Length; IF (Size> 0) {streamwriter.write (DATA, 0, SIZE);} Else {Break;}}. }}} After the compression and decompression class, it is necessary to call in the form. how? Is it a newbie, will not be called? OK, then look down on how to call in the form. First put two command buttons in the form (don't tell me you don't put it ~), then write the following source code /// Private void button2_click_1 (Object sender, system.eventargs e) {string [] fileproperties = new string [2]; fileproperties [0] = "c: / unzipped /"; // to be compressed file directory fileproperties [1] = "C : / zip/a.zip "; // Compressed target file zipclass zc = new zipClass (); zc.zipfilemain;} Private void button2_click (object sender, system.eventargs e) {string [] fileproperties = new string [2]; fileproperties [0] = "c: /zip/test.zip"; // To decompressed file fileproperties [1] = "C: / unzipped /"; // Decompressed target directory unzipClass unzc = new unzipClass (); unzc.unzip (fileproperties);}