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