In .net 4.5 Framework, we can zip a file by this 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# zip file and folder programmatically的更多相关文章

  1. Java ZIP File Example---refernce

    In this tutorial we are going to see how to ZIP a file in Java. ZIP is an archive file format that e ...

  2. [转]SharePoint 2010 Download as Zip File Custom Ribbon Action

    在SharePoint 2010文档库中,结合单选框,在Ribbon中提供了批量处理文档的功能,比如,批量删除.批量签出.批量签入等,但是,很遗憾,没有提供批量下载,默认的只能一个个下载,当选择多个文 ...

  3. How to create a zip file in NetSuite SuiteScript 2.0 如何在现有SuiteScript中创建和下载ZIP压缩文档

    Background We all knows that: NetSuite filecabinet provided a feature to download a folder to a zip ...

  4. 记一个mvn奇怪错误: Archive for required library: 'D:/mvn/repos/junit/junit/3.8.1/junit-3.8.1.jar' in project 'xxx' cannot be read or is not a valid ZIP file

    我的maven 项目有一个红色感叹号, 而且Problems 存在 errors : Description Resource Path Location Type Archive for requi ...

  5. linux下解压大于4G文件提示error: Zip file too big错误的解决办法

    error: Zip file too big (greater than 4294959102 bytes)错误解决办法.zip文件夹大于4GB,在centos下无法正常unzip,需要使用第三方工 ...

  6. maven install 读取jar包时出错;error in opening zip file

    错误信息: [INFO] ------------------------------------------------------------------------ [ERROR] Failed ...

  7. The specified file or folder name is too long

    You receive a "The specified file or folder name is too long" error message when you creat ...

  8. error in opening zip file 1 错误

    项目部署服务启动时会出现: error in opening zip file 1 错误 原来是不同服务器编译过的jar包直接下载后发布有问题,重新上传本地编译好的lib下面的jar包后,启动服务,正 ...

  9. The URL "filename" is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web

    Sharepoint Error : The URL "filename" is invalid. It may refer to a nonexistent file or fo ...

随机推荐

  1. 教你爱上Blocks(闭包)

    传值 Blocks是C语言的扩充功能:带有自动变量(局部变量)的匿名函数.通过Blocks,源代码中就能使用匿名函数,即不带名称的函数.在我们 的工作中,命名占据了很大一部分,函数名,变量名,属性名, ...

  2. JavaSE思维导图(六)

  3. 关于 rand() 函数返回值的值域的疑问

    <C语言参考手册>中关于 rand() 函数有如下描述. (1)rand() 函数的原型 int rand(void); (2)连续调用 rand 将返回 0 到 int 类型的最大可表示 ...

  4. QR Code簡介、介紹

    QR Code為目前最常被使用的一種二維條碼,1994年由日本Denso-Wav e公司發明,QR是英文Qu ickResponse的縮寫,即快速反應的意思,1999年時,公布了符合日本當地的標準-「 ...

  5. file_get_contents post数据

    //默认模拟的header头 private function _defaultHeader() { $header = "User-Agent:Mozilla/5.0 (Windows; ...

  6. android 解决ViewPager双层嵌套的滑动问题

    解决ViewPager双层嵌套的滑动问题 今天我分享一下ViewPager的双层嵌套时影响内部ViewPager的触摸滑动问题 之前在做自己的一个项目的时候,遇到广告栏图片动态切换,我第一时间想到的就 ...

  7. HDU 1012 u Calculate e

    题解:直接模拟 #include <cstdio> int main(){ puts("n e");puts("- -----------");pu ...

  8. Linux 电子书共享下载--大家一起学习

    文件名 大小 时间 到期时间 操作    鸟哥私房菜(全集).pdf 36.57 MB 2 小时前 免费永久       练成Linux高手.chm 3.76 MB 2 小时前 免费永久        ...

  9. YY前端笔试总结

    1.一个元素float以后.为什么要清除浮动?清除浮动的方法有哪些? 浮动确实是经经常使用,也知道清除浮动的必要性.但要我道个所以然,还是得绞尽脑汁.我个人的理解是,当一个元素float以后,就脱离正 ...

  10. String、StringBuffer和StringBuild的区别

    public class Test1 { public static void stringReplace (String text) { text = text.replace('j','i') ; ...