c# zip file and folder programmatically
2015-11-20 15:07
573 查看
In .net 4.5 Framework, we can zip a file by this way:
zip a folder and unzip in a easy way:
private static string CompressFile(string sourceFileName) { using (ZipArchive archive = ZipFile.Open(Path.ChangeExtension(sourceFileName, ".zip"), ZipArchiveMode.Create)) { archive.CreateEntryFromFile(sourceFileName, Path.GetFileName(sourceFileName)); } return Path.ChangeExtension(sourceFileName, ".zip"); }
zip a folder and unzip in a easy way:
private static void CompressFloder(string startPath, string zipPath) { ZipFile.CreateFromDirectory(startPath, zipPath); } private static void UncompressToDirectory(string zipPath, string extractPath) { ZipFile.ExtractToDirectory(zipPath, extractPath); }
相关文章推荐
- C#网页数据采集(二)WebBrowser
- 转载:C#中的泛型
- c#_Diff_Between_NormalCom_And_ComInDotNet
- C#根据文件流判断文件类型
- C#中进行单元测试
- C#中Trim()、TrimStart()、TrimEnd()的用法
- C#中的内存四区
- C#程序集编译输出XML文档的作用
- KING_C#学习之QRCode二维码(一)——基础知识扫盲
- C# winform控件之弹出窗口学习积累
- String Format for DateTime [C#]
- List集合Null值判断新技能
- Mono为何能跨平台?聊聊CIL(MSIL)
- c# process 获取进程退出码
- 字符串拼接新技能
- C# 自定义等待窗口
- .NET进阶系列之一:C#正则表达式整理备忘
- 匹夫细说C#:庖丁解牛迭代器,那些藏在幕后的秘密
- 委托的简化语法,聊聊匿名方法和闭包
- c#的AOP实现,面向领域编程