DoNetZip类库解压和压缩文件
using Ionic.Zip; public class ZipHelper { public static void ZipSingleFile(string zipPath) { try { using (ZipFile zip = new ZipFile()) { zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images"); zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files"); zip.AddFile("ReadMe.txt"); zip.Save(zipPath); } } catch (Exception ex) { System.Console.Error.WriteLine("exception: " + ex); } } public static void UnZipSingleFile(string path) { try { using (ZipFile zip = new ZipFile(path)) { var baseDir = Path.GetDirectoryName(path); var fileName = Path.GetFileNameWithoutExtension(path); var newDir = Path.Combine(baseDir, fileName); Directory.CreateDirectory(newDir);
zip.Password = "paw";//如果需要密码的话可以加上这句 zip.ExtractAll(newDir, ExtractExistingFileAction.OverwriteSilently); } File.Delete(path); } catch(Exception ex) { System.Console.Error.WriteLine("exception: " + ex); } } }