码迷,mamicode.com
首页 > 其他好文 > 详细

Zip 压缩

时间:2017-01-20 12:38:31      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:finish   word   sharp   dll   path   write   pfile   cto   director   

ICSharpCode.SharpZipLib.dll

 

using ICSharpCode.SharpZipLib.Zip;

 

string[] filenames = Directory.GetFiles(dirPath);
using (ZipOutputStream s = new ZipOutputStream(File.Create(zipFilePath)))
{
s.Password = password;
s.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
if (file.Contains(fileName))
{
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
}
s.Finish();
s.Close();
}

Zip 压缩

标签:finish   word   sharp   dll   path   write   pfile   cto   director   

原文地址:http://www.cnblogs.com/Andy-Li/p/6322386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!