DoNetZip类库解压和压缩文件
Posted dayang12525
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.ExtractAll(newDir, ExtractExistingFileAction.OverwriteSilently); } File.Delete(path); } catch(Exception ex) { System.Console.Error.WriteLine("exception: " + ex); } } }
以上是关于DoNetZip类库解压和压缩文件的主要内容,如果未能解决你的问题,请参考以下文章