C # Extract and compress file source code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.