使用C#压缩文件的最好方法是什么?理想情况下,我希望能够将文件分离到单个归档中。
发布于 2009-11-03 19:51:20
您可以使用DotNetZip来确定这一点。它可以在任何应用程序中免费使用。
下面是一些示例代码:
try
{
// for easy disposal
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
// add the report into a different directory in the archive
zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
zip.AddFile("ReadMe.txt");
zip.Save("MyZipFile.zip");
}
}
catch (System.Exception ex1)
{
System.Console.Error.WriteLine("exception: " + ex1);
}发布于 2012-11-16 05:15:39
如果您使用的是4.5+版本,则现在已将其内置到框架中
否则,请使用Ionic。
命名空间为System.IO.Packaging.ZIPPackage。
请看http://visualstudiomagazine.com/articles/2012/05/21/net-framework-gets-zip.aspx上的一个故事。
发布于 2009-11-03 19:50:33
你有没有看过SharpZipLib
我相信您可以使用System.IO.Packaging名称空间中的类来构建zip文件--但每次我尝试查看它时,我都会发现它相当混乱……
https://stackoverflow.com/questions/1666824
复制相似问题