#region Ionic.zip Compressed File//compression method a public void Execompone () {String FileName = DateTime.Now.To String ("YYMMDDHHMMSSFF"); ZipFile instantiates a compressed file to save the path of an object zip using (zipfile zip = new ZipFile (@ "e:\\yangfeizai\\" + filename+ ". zip", encoding.d Efault)) {//Encrypt compressed zip. Password = "123456"; Add the folder you want to compress to the Zip object (the folder path and name to compress) zip. Adddirectory (@ "e:\\yangfeizai\\" + "12051214544443"); Add the file you want to compress to the Zip object, if the file does not have the wrong filenotfoundexcept//zip. AddFile (@ "e:\\yangfeizai\\12051214544443\\" + "Jayzai.xml"); Zip. Save (); }}//compression method two public void Execomptwo () {String FileName = DateTime.Now.ToString ("yy MMDDHHMMSSFF "); ZipFile instantiation of an object zip using (zipfile zip = new ZipFile ()) {//encryption compression ZIP.P Assword = "123456"; Add the folder you want to compress to the Zip object (the file to compressFolder path and name) zip. Adddirectory (@ "e:\\yangfeizai\\" + "12051214544443"); Add the file you want to compress to the Zip object, if the file does not have the wrong filenotfoundexcept//zip. AddFile (@ "e:\\yangfeizai\\12051214544443\\" + "Jayzai.xml"); Save the compressed file with the save overloaded method in the Zip object, and the parameter is the path zip that holds the compressed file. Save (@ "e:\\yangfeizai\\" + FileName + ". zip"); }} #endregion #region//delete files in//3. Remove a file from the zip file, note that you cannot delete a folder directly public void Exedelet E (string FileName) {using (ZipFile zip = Zipfile.read (@ "e:\\yangfeizai\\" + FileName + ". zip")) {//zip["jayzai.xml"] = null; Remove a zip file from the Zip object. RemoveEntry ("Jayzai.xml"); Zip. Save (); }} #endregion
C # ZIP Compression Ionic.Zip.dll