Which method do you think is the "best".
你认为哪种方法是最好的?
- Use the
System.IO.Packaging
namespace? - 先使用。包装名称空间?
- Use interop with the Shell?
- 使用互操作与外壳?
- Third party library for .NET?
- .NET的第三方库?
- Interop with open source unmanaged DLL?
- 与开放源码非托管DLL进行互操作?
[I can target Framework 3.5; best = easiest to design, implement, and maintain.]
[我的目标是框架3.5;best =最容易设计、实现和维护。
I am mostly interested in why you think the chosen approach is best.
我最感兴趣的是为什么你认为选择的方法是最好的。
8 个解决方案
#1
23
I've always used SharpZipLib
我总是SharpZipLib使用
Forgot the why part: Mainly because its been around for a long time. It is well documented, and has an intuitive API. Plus it's open source if you're into that type of thing.
忘记为什么部分:主要是因为它已经存在很长一段时间了。它有很好的文档,并且具有直观的API。加上它是开源的,如果你喜欢这种类型的东西。
#2
16
I've found the DotNetZip Library to be this easiest way to work with zip files. SharpZipLib is a far more powerful and flexible solution.
我发现DotNetZip库是处理zip文件的最简单方法。SharpZipLib是一个强大得多、灵活得多的解决方案。
#3
16
DotNetZip is very simple to use. I like it because it is fully-managed - no shell interaction required. The programming model is simpler and cleaner than that for the shell. Also it is simpler than SharpZipLib as well as the Packaging classes added in .NET 3.0. It is free, small, actively maintained.
DotNetZip使用起来非常简单。我喜欢它,因为它是完全托管的——不需要shell交互。编程模型比shell更简单、更简洁。它也比SharpZipLib和。net 3.0中添加的打包类更简单。它是免费的,小的,积极维护的。
It is much better than the J# option that one poster offered - J# is a huge runtime and a giant pill to swallow to get just ZIP support. Also J# support is being discontinued. Probably not a good idea to introduce new dependencies on J#.
它比一个海报所提供的j#选项要好得多——j#是一个巨大的运行时,它是一个巨大的药丸,可以吞下去,得到的只是ZIP支持。此外,j#支持也被停止。在j#上引入新的依赖性可能不是一个好主意。
Example code for DotNetZip:
DotNetZip示例代码:
try
{
using (ZipFile zip = new ZipFile(args[0], System.Console.Out))
{
zip.AddDirectory(args[1]); // recurses subdirectories
zip.Save();
}
}
catch (System.Exception ex1)
{
System.Console.Error.WriteLine("exception: " + ex1);
}
DotNetZip works with .NET v2.0, 3.0, 3.5 as well as Compact Framework v2.0 and 3.5. It does ZIP files, Unicode filenames, comments, passwords. It does ZIP64 as well as Self-extracting archives. It's FAST. Try it.
DotNetZip支持。net v2.0、3.0、3.5以及紧凑框架v2.0和3.5。它可以压缩文件、Unicode文件名、注释和密码。它不仅做ZIP64,而且还做自提取归档。这是太快了。试一试。
#4
14
I realise that this is an old question now, but I just thought I'd add a more up to date answer. If you are using .NET 4.5, then you can programmatically save multiple files into a zip folder easily using the new built in ZipFile
class.
我意识到这是一个老问题了,但我想我应该再加上一个最新的答案。如果您正在使用。net 4.5,那么您可以使用ZipFile类中新建的文件轻松地以编程方式将多个文件保存到zip文件夹中。
First, you'll need to prepare your files into a new folder (Directory.CreateDirectory
, File.Move
) and then you can simply use the ZipFile.CreateFromDirectory
Method (adapted from the linked page):
首先,您需要将文件准备到一个新的文件夹(目录)中。然后您可以使用ZipFile。CreateFromDirectory方法(改编自链接页面):
string filePathOfNewFolder = @"c:\example\start";
string zipFilePath = @"c:\example\result.zip";
ZipFile.CreateFromDirectory(filePathOfNewFolder, zipFilePath);
#5
2
Since you're targetting Framework 3.5, I'd go with System.IO.Packaging
. It's a library designed specifically for zipping, and comes with the framework so there's not even an extra DLL needed by the product. The usage example is atrocious, though.
既然你在使用框架3.5,我就用System.IO.Packaging。它是一个专门为zipping设计的库,并且带有框架,因此产品甚至不需要额外的DLL。不过,这个用法的例子很糟糕。
Using the shell is unrecommended. First, it would only work on Windows XP and above. But even if you don't care about that, it's pitfalls are quite numerous (I've done it before, but only because I really had no choice).
不建议使用shell。首先,它只适用于Windows XP及以上版本。但是,即使您不关心这个,它的缺陷也是相当多的(我以前做过,但只是因为我真的别无选择)。
if you're not targetting 3.5, I'd use SharpZipLib
. It's quite a good library, and even if you are using 3.5 you might consider it.
如果你不喜欢3。5,我就用ziplib。这是一个很好的库,即使你正在使用3.5,你也可以考虑使用它。
#6
2
The GZipStream and DeflateStream classes under System.IO.Compression namespace make it pretty easy to zip things up.
System.IO下的GZipStream和DeflateStream类。压缩命名空间使压缩变得非常容易。
UPDATE: Comments correctly state that these classes do not allow you to manipulate a Zip file. However, the J# dlls contain the required functionality in java.util and java.io namespaces. For more details see the Code Project article by dmihailescu which details their use and provides sample code.
更新:注释正确地声明这些类不允许您操作Zip文件。然而,j# dll在java中包含所需的功能。util和java。io命名空间。有关更多细节,请参阅dmihailescu的代码项目文章,其中详细介绍了它们的使用并提供了示例代码。
#7
2
No one has mentioned the Xceed Zip component. I've used it before and it worked excellent for creating zip files and compressing data streams. I highly recommend it but there may be a license fee tradeoff.
没有人提到Xceed Zip组件。我以前用过它,它在创建zip文件和压缩数据流方面非常有用。我强烈推荐它,但可能有一个许可证费用权衡。
#8
0
Ultimate ZIP is a high-performance and reliable compression component which lets you easily create and manipulate ZIP, TAR, TGZ, GZ archives on-the-fly as well as browse the contents of a previously created archive right in your .NET cross-platform apps. Written purely in C# with the best design patterns and low-level .NET optimizations applied, it offers performance, reliability and extensibility to your .NET applications. The package comes with a number of code snipets and fully documented examples in VB.NET and C# illustrating how to create, zip and unzip archives.
Ultimate ZIP是一个高性能、可靠的压缩组件,它可以让您轻松地创建和操作ZIP、TAR、TGZ、GZ存档以及浏览. net跨平台应用程序中先前创建的归档文件的内容。完全用c#编写,应用了最佳的设计模式和底层的。net优化,它为。net应用程序提供了性能、可靠性和可扩展性。该包附带了许多代码片段和VB中完整的文档示例。NET和c#说明如何创建、压缩和解压归档。
Ultimate ZIP component for .NET
.NET的终极压缩组件
#1
23
I've always used SharpZipLib
我总是SharpZipLib使用
Forgot the why part: Mainly because its been around for a long time. It is well documented, and has an intuitive API. Plus it's open source if you're into that type of thing.
忘记为什么部分:主要是因为它已经存在很长一段时间了。它有很好的文档,并且具有直观的API。加上它是开源的,如果你喜欢这种类型的东西。
#2
16
I've found the DotNetZip Library to be this easiest way to work with zip files. SharpZipLib is a far more powerful and flexible solution.
我发现DotNetZip库是处理zip文件的最简单方法。SharpZipLib是一个强大得多、灵活得多的解决方案。
#3
16
DotNetZip is very simple to use. I like it because it is fully-managed - no shell interaction required. The programming model is simpler and cleaner than that for the shell. Also it is simpler than SharpZipLib as well as the Packaging classes added in .NET 3.0. It is free, small, actively maintained.
DotNetZip使用起来非常简单。我喜欢它,因为它是完全托管的——不需要shell交互。编程模型比shell更简单、更简洁。它也比SharpZipLib和。net 3.0中添加的打包类更简单。它是免费的,小的,积极维护的。
It is much better than the J# option that one poster offered - J# is a huge runtime and a giant pill to swallow to get just ZIP support. Also J# support is being discontinued. Probably not a good idea to introduce new dependencies on J#.
它比一个海报所提供的j#选项要好得多——j#是一个巨大的运行时,它是一个巨大的药丸,可以吞下去,得到的只是ZIP支持。此外,j#支持也被停止。在j#上引入新的依赖性可能不是一个好主意。
Example code for DotNetZip:
DotNetZip示例代码:
try
{
using (ZipFile zip = new ZipFile(args[0], System.Console.Out))
{
zip.AddDirectory(args[1]); // recurses subdirectories
zip.Save();
}
}
catch (System.Exception ex1)
{
System.Console.Error.WriteLine("exception: " + ex1);
}
DotNetZip works with .NET v2.0, 3.0, 3.5 as well as Compact Framework v2.0 and 3.5. It does ZIP files, Unicode filenames, comments, passwords. It does ZIP64 as well as Self-extracting archives. It's FAST. Try it.
DotNetZip支持。net v2.0、3.0、3.5以及紧凑框架v2.0和3.5。它可以压缩文件、Unicode文件名、注释和密码。它不仅做ZIP64,而且还做自提取归档。这是太快了。试一试。
#4
14
I realise that this is an old question now, but I just thought I'd add a more up to date answer. If you are using .NET 4.5, then you can programmatically save multiple files into a zip folder easily using the new built in ZipFile
class.
我意识到这是一个老问题了,但我想我应该再加上一个最新的答案。如果您正在使用。net 4.5,那么您可以使用ZipFile类中新建的文件轻松地以编程方式将多个文件保存到zip文件夹中。
First, you'll need to prepare your files into a new folder (Directory.CreateDirectory
, File.Move
) and then you can simply use the ZipFile.CreateFromDirectory
Method (adapted from the linked page):
首先,您需要将文件准备到一个新的文件夹(目录)中。然后您可以使用ZipFile。CreateFromDirectory方法(改编自链接页面):
string filePathOfNewFolder = @"c:\example\start";
string zipFilePath = @"c:\example\result.zip";
ZipFile.CreateFromDirectory(filePathOfNewFolder, zipFilePath);
#5
2
Since you're targetting Framework 3.5, I'd go with System.IO.Packaging
. It's a library designed specifically for zipping, and comes with the framework so there's not even an extra DLL needed by the product. The usage example is atrocious, though.
既然你在使用框架3.5,我就用System.IO.Packaging。它是一个专门为zipping设计的库,并且带有框架,因此产品甚至不需要额外的DLL。不过,这个用法的例子很糟糕。
Using the shell is unrecommended. First, it would only work on Windows XP and above. But even if you don't care about that, it's pitfalls are quite numerous (I've done it before, but only because I really had no choice).
不建议使用shell。首先,它只适用于Windows XP及以上版本。但是,即使您不关心这个,它的缺陷也是相当多的(我以前做过,但只是因为我真的别无选择)。
if you're not targetting 3.5, I'd use SharpZipLib
. It's quite a good library, and even if you are using 3.5 you might consider it.
如果你不喜欢3。5,我就用ziplib。这是一个很好的库,即使你正在使用3.5,你也可以考虑使用它。
#6
2
The GZipStream and DeflateStream classes under System.IO.Compression namespace make it pretty easy to zip things up.
System.IO下的GZipStream和DeflateStream类。压缩命名空间使压缩变得非常容易。
UPDATE: Comments correctly state that these classes do not allow you to manipulate a Zip file. However, the J# dlls contain the required functionality in java.util and java.io namespaces. For more details see the Code Project article by dmihailescu which details their use and provides sample code.
更新:注释正确地声明这些类不允许您操作Zip文件。然而,j# dll在java中包含所需的功能。util和java。io命名空间。有关更多细节,请参阅dmihailescu的代码项目文章,其中详细介绍了它们的使用并提供了示例代码。
#7
2
No one has mentioned the Xceed Zip component. I've used it before and it worked excellent for creating zip files and compressing data streams. I highly recommend it but there may be a license fee tradeoff.
没有人提到Xceed Zip组件。我以前用过它,它在创建zip文件和压缩数据流方面非常有用。我强烈推荐它,但可能有一个许可证费用权衡。
#8
0
Ultimate ZIP is a high-performance and reliable compression component which lets you easily create and manipulate ZIP, TAR, TGZ, GZ archives on-the-fly as well as browse the contents of a previously created archive right in your .NET cross-platform apps. Written purely in C# with the best design patterns and low-level .NET optimizations applied, it offers performance, reliability and extensibility to your .NET applications. The package comes with a number of code snipets and fully documented examples in VB.NET and C# illustrating how to create, zip and unzip archives.
Ultimate ZIP是一个高性能、可靠的压缩组件,它可以让您轻松地创建和操作ZIP、TAR、TGZ、GZ存档以及浏览. net跨平台应用程序中先前创建的归档文件的内容。完全用c#编写,应用了最佳的设计模式和底层的。net优化,它为。net应用程序提供了性能、可靠性和可扩展性。该包附带了许多代码片段和VB中完整的文档示例。NET和c#说明如何创建、压缩和解压归档。
Ultimate ZIP component for .NET
.NET的终极压缩组件