在 .NET 4.0 中处理 Zip 文件而无需第三方库?
这里有一个关于 3.5 的类似问题:
推测 4.0 会有它,但我找不到任何有关它的信息。如果没有,有人知道为什么吗?看起来它在需要支持的事情列表中相当靠前。
There is a similar question for 3.5 here:
Is there a built-in zip library in .NET 3.5?
that speculated that 4.0 would have it, but I can't find any info about it. If not, does anyone know why not? Seems like it would be fairly high on the list of things to include support for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 System.IO.Packaging 命名空间,其中包含对 ZIP 文件的支持,但不是 ZIP 文件的所有功能。
不过,这可能足以满足您的需求。
Take a look at the System.IO.Packaging namespace, which contains support for ZIP files, but not all of the features of ZIP files.
Still, it might be enough for your needs.
您可能已经开始学习,但 .NET 4.5 中添加了 ZiP API
http: //msdn.microsoft.com/en-us/library/system.io.compression.ziparchive.aspx
发疯。
You may have already moved along, but ZiP API is added in .NET 4.5
http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive.aspx
go nuts.
不适用于 4.0,但正在考虑在下一个版本中使用
ZipArchive
类。您可以在 BCL 团队博客。编辑:否则,假设它仍然可用,并且根据您对内置的定义(至少它与 Visual Studio 一起提供),您也许能够使用 J# 类来压缩文件,如本文所述:使用 J# 类库中的 Zip 类来压缩文件和数据C#
Edit2:尽管请注意下面的注释,但 J# 选项可能不是正确的选项,除非在某些特殊情况下。
Not for 4.0, but a
ZipArchive
class is being considered for the next version. You can find details about this on the BCL Team blog.Edit: Otherwise, assuming that it's still available, and depending on your definition of built in (at least it comes/came with Visual Studio), you might be able to use the J# classes to zip files as described in this article: Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#
Edit2: Though note the comments below, that the J# option is probably not the right option except in certain unusual circumstances.
最容易处理的是这里的示例代码。
您需要添加一个新程序集才能找到他的 Zip 存档。
在 .NET 4.5 中使用 Zip 文件
Most easiest to deal with, is with sample code here.
You need to add a new assembly just to find he Zip archive.
Working with Zip files in .NET 4.5