c# zip file and folder programmatically
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的更多相关文章
- 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 ...
- [转]SharePoint 2010 Download as Zip File Custom Ribbon Action
在SharePoint 2010文档库中,结合单选框,在Ribbon中提供了批量处理文档的功能,比如,批量删除.批量签出.批量签入等,但是,很遗憾,没有提供批量下载,默认的只能一个个下载,当选择多个文 ...
- 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 ...
- 记一个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 ...
- linux下解压大于4G文件提示error: Zip file too big错误的解决办法
error: Zip file too big (greater than 4294959102 bytes)错误解决办法.zip文件夹大于4GB,在centos下无法正常unzip,需要使用第三方工 ...
- maven install 读取jar包时出错;error in opening zip file
错误信息: [INFO] ------------------------------------------------------------------------ [ERROR] Failed ...
- 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 ...
- error in opening zip file 1 错误
项目部署服务启动时会出现: error in opening zip file 1 错误 原来是不同服务器编译过的jar包直接下载后发布有问题,重新上传本地编译好的lib下面的jar包后,启动服务,正 ...
- 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 ...
随机推荐
- 微信开发-Jssdk调用分享实例
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO ...
- IIS7.5(IIS7)配置伪静态urlrewrite
找了好久,终于找到了.已经测试通过,收藏. 转载自:http://jingyan.baidu.com/article/67508eb4ff92c69cca1ce49a.html 首先新建一个应用程序池 ...
- 最小生成树Jungle Roads
这道题一定要注意录入方式,我用的解法是prime算法 因为单个字符的录入会涉及到缓冲区遗留的空格问题,我原本是采用c语言的输入方法录入数据的,结果对了,但是提交却一直wrong,后来改成了c++的ci ...
- USACO Section 5.1 Fencing the Cows(凸包)
裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...
- Collections之sort的两个方法(自然排序和自定义比较器排序)
Collections是个服务于Collection的工具类(静态的),它里面定义了一些集合可以用到的方法. 本文演示了Collections类里sort()的两个方法.第一种只需传入被排序的集合,便 ...
- python cmd命令调用
关于python调用cmd命令: 主要介绍两种方式: 1.python的OS模块. OS模块调用CMD命令有两种方式:os.popen(),os.system(). 都是用当前进程来调用. os.sy ...
- jQuery.validationEngine前端验证
引入相关文件: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js" type ...
- get the execution time of a sql statement.
declare @d datetimeset @d = GETDATE()select * from dbo.spt_valuesselect [语句执行花费时间(毫秒)]= DATEDIFF(ms, ...
- Mirantis Certification summary
preface Mirantis Certification (MCA100 )summary roughly question types handy remain by Ruiy!
- javascrip cookie
首先要明白一下cookie的概念.由于HTTP协议是一种无状态协议,也就是说一旦server和client的数据交换完成后,他们之间的连接就会被断开.再次交换数据的时候就须要再次建立连接.这就意味着s ...