Zip Multiple Files with SharpZipLib.dll

Source: Internet
Author: User
Tags crc32

Nuget Installation: Install-package ICSharpCode.SharpZipLib.dll

Private voidWritezipfile (string[] Filestozip,stringWritetofilepath) {            Try{CRC32 CRC=NewCrc32 (); Zipoutputstream s=NewZipoutputstream (System.IO.File.Create (Writetofilepath)); S.setlevel (9);//0-store-9-means best Compression                 for(inti =0; i < filestozip.length; i++)                {                    //must use a relative path where so, files show up in the Windows Zip File Viewer//.. hence the use of Path.getfilename (...)ZipEntry entry =NewZipEntry (Path.getfilename (filestozip[i)); Entry. DateTime=DateTime.Now; //Read in the                    using(FileStream fs =System.IO.File.OpenRead (Filestozip[i])) {                        byte[] buffer =New byte[FS.                        Length]; Fs. Read (Buffer,0, buffer.                        Length); //set Size and the CRC, because the information//About the size and CRC should is stored in the header//if it isn't set it is automatically written in the footer. //(In this case size = = CRC = =-1 in the header)//Some zip Programs has 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 (entry); S.write (Buffer,0, buffer.                    Length);                }} s.finish ();            S.close (); }            Catch(Exception ex) {HttpContext.Trace.Warn (ex).            ToString ()); }        }

Zip multiple files with SharpZipLib.dll

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.