Using system.io;using system.windows.forms;using icsharpcode.sharpziplib.zip;using ICSharpCode.SharpZipLib.Checksums; public void UnZip (string strsoucefile, String strdestfile) {if (! Directory.Exists (strDestFile)) directory.createdirectory (strDestFile); using (zipinputstream zip = new Zipinputstream (File.openread (strsoucefile))) {ZipEntry theentry ; String FileName; FileStream StreamWriter; while (Theentry = zip. Getnextentry ()) = null) {FileName = Path.getfilename (theentry.name); if (fileName! = String.Empty) {streamWriter = new FileStream (strDestFile + F Ilename, FileMode.Create, FileAccess.Write, FileShare.Read | Fileshare.write); int size = 2048; byte[] data = new byte[2048]; while (true) {size = zip. Read (data, 0, data. Length); if (Size > 0) {streamwriter.write (data, 0, size); } else {break; }} streamwriter.close (); }} MessageBox.Show ("Unzip the file successfully!"," hint ", messageboxbuttons.ok,messageboxicon.information); }} public void ZipFile (string strsoucefile, String strdestfile) {using (Zipoutputstream stream = new Zipoutputstream (File.create (strDestFile))) {stream. SetLevel (5); byte[] buffer = new byte[0x1000]; ZipEntry entry = new ZipEntry (Path.getfilename (strsoucefile)); Entry. DateTime = DateTime.Now; Stream. Putnextentry (entry); using (FileStream stream2 = File.openread (strsoucefile)) {int num; do {num = stream2. Read (buffer, 0, buffer. Length); Stream. Write (buffer, 0, num); } while (num > 0); MessageBox.Show ("Compressed file succeeded!
"); } stream. Finish (); Stream. Close (); } }
DLL that needs to be referenced, download DLL for page below
http://download.csdn.net/detail/sky_cat/7236675
C # Extract and compress file source code