Use ICSharpCode.SharpZipLib.dll Download: http: //www.icsharpcode.net/OpenSource/SharpZipLib/using ICSharpCode.SharpZipLib.GZip; using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; Code: the files to private Void btnzip_click (object sender, system.eventargs e) {string filename; zipoutputstream zos; filestream fs;
CRC32 CRC = New CRC32 ();
OpenFiledialog OpenFileDialog = New OpenFiledialog ();
//openfiledialog.initialdirectory = "c: //"; openfiledialog.filter = "txt files (* .txt) | * .txt | all files (*. *) | *. *"; openfiledialog.filterIndex = 2; OpenFileDialog .Restoredirectory = false;
IF (OpenFileDialog.Showdialog () == DialogResult.ok) {filename = path.getFileName (OpenFiledialog.FileName);
ZOS = New ZipOutputStream (file.create (filename ".zip");
Zos.SetLevel (6);
FS = file.openread (filename);
Byte [] buffer = new byte [fs.length]; fs.read (buffer, 0, buffer.length); this.richtextBox1.text = encoding.utf8.getstring (buffer); zipentry entry = new zipentry (filename); Entry.datetime = datetime.now; entry.size = fs.length;
fs.close ();
Crc.reset (); crc.Update (buffer); entry.crc = crc.value; zos.putNextentry; zos.write (buffer, 0, buffer.length);
Zos.Finish (); zos.close ();}} Compressed to memory private void btnziponeText_click (Object sender, system.eventargs e) {msfilein = new memorystream ();
//this.statusbarpanel1.text= "The data is being compressed in the first text box ..."; byte [] getchr = encoding.utf8.getbytes (this.richtextbox1.text.tostring ());
ZipOutputStream zos = new ZipOutputStream (msFileIn); zos.SetLevel (6); ZipEntry entry = new ZipEntry ( "Stream"); Crc32 crc = new Crc32 (); crc.Reset (); crc.Update (getchr); entry. CRC = crc.value; entry.datetime = datetime.now; entry.size = getChr.Length; zos.putNextentry (entry); zos.write (getchr, 0, getchr.length);
ZOS.FINISH (); zos.close ();
Messagebox.show ("Compression, the result is stored in memory!"); //This.statusbarpanel1.text = "The data compression in the first text box is completed.";} Decompressed file private void btnunzip_click (Object Sender, System. Eventargs e) {string filename;
OpenFiledialog OpenFileDialog = New OpenFiledialog ();
//openfiledialog.initialdirectory = "c: //"; openfiledialog.filter = "txt files (* .txt) | * .txt | all files (*. *) | *. *"; openfiledialog.filterIndex = 2; OpenFileDialog .Restoredirectory = false;
IF (OpenFileDialog.Showdialog () == DialogResult.ok) {filename = path.getFileName (OpenFiledialog.FileName);
ZipInputStream zis = new ZipInputStream (File.OpenRead (filename)); ZipEntry theEntry; while (! (TheEntry = zis.GetNextEntry ()) = null) {// string directoryName = Path.GetDirectoryName (theEntry.Name); // Directory .CreatedIRectory (DirectoryName)
String filename = path.getFileName (thents.name);