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. 应用java多线程实现server端与多client之间的通信

    应用多线程来实现server与多线程之间的通信的基本步骤 1.server端创建ServerSocket,循环调用accept()等待client链接 2.client创建一个Socket并请求和se ...

  2. Cocos2D-x权威指南:核心类成员CCNode

    节点类(CCNode)是Cocos2D-x中的主要类,继承自CCObject.继承关系如图3-2所看到的. 不论什么须要画在屏幕上的对象都是节点类. 最经常使用的节点类包含场景类(CCScene).布 ...

  3. Java 处理json经常使用代码

    本project代码已上传至资源,如有须要,请自行下载. package com.michael; import static org.junit.Assert.assertEquals; impor ...

  4. 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)

    前言 本章将实现非常实用的功能——下载在线视频.涉及到多线程.线程更新UI等技术,还需思考产品的设计,如何将新加的功能更好的融入到现有的产品中,并不是简单的加一个界面就行了,欢迎大家交流产品设计和技术 ...

  5. SAN实现

    Linux 上主要有三个 iSCSI Target(基于internet scsi协议的target) 实现: Linux SCSI Target – STGT / tgt Linux-IO Targ ...

  6. 显示标题栏中标题左侧的小图icon

    如何显示网站logo,定义网站收藏夹图标 代码与解释 <link rel="shortcut icon" href="/path/favicon.ico" ...

  7. Android App开发常用专题开源代码

    Android App开发中用到过的专题类开源代码: 项目的需求多了,不知不觉成了Github摘抄员,感谢分享精神,节省了很多弯路和时间.不过想要实现指定效果,还是要看懂作者的思路才好下手改造. 主题 ...

  8. windows下nginx+tomcat分布式集群部署

    首先官网下载  http://nginx.org/en/download.html,我的本地环境为 实现的架构: 从图上可以看出,nginx作为负载均衡请求分发器,当请求A应用时候,分发到A集群,同理 ...

  9. less 工具

    less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面翻 ...

  10. phome_enewsclass 数据表字段解释(栏目主表)

    字段名 类型 解释 附加说明 classid smallint(6) 栏目ID   bclassid smallint(6) 父栏目ID   classname varchar(50) 栏目名称   ...