简体   繁体   English

如何在.net framework 4.0中压缩文件夹

[英]How to Zip A folder in .net framework 4.0

How to zip a folder using vb.net and in .net framework 4.0. 如何使用vb.net和.net framework 4.0压缩文件夹。 I am able to do this by using ZipFile class which is available in framework 4.5 but I need to use only framework 4.0 and also no third party library. 我能够通过使用框架4.5中提供的ZipFile类来实现这一点,但我只需要使用框架4.0,也没有第三方库。 Please help 请帮忙

Actually you can use the ZipFile class in .NET 4.0 as well. 实际上你也可以在.NET 4.0中使用ZipFile类。 You just gotta add a reference to the System.IO.Compression.FileSystem.dll file, located in: 您只需要添加对System.IO.Compression.FileSystem.dll文件的引用,该文件位于:

%SystemRoot%\Microsoft.NET\assembly\GAC_MSIL\System.IO.Compr‌​‌​‌​ession.FileSyste‌​m\‌​v4‌​.0_4.0.0.0__‌​b77a‌​5c56‌​1934e089‌​\Syste‌​m.IO.C‌​ompr‌​ession.F‌​ileSyste‌​‌​m.dll

As you see it is located in the "v4.0" folder, so it exists in .NET 4.0, but for some reason isn't referenced automatically. 如您所见,它位于“v4.0”文件夹中,因此它存在于.NET 4.0中,但由于某种原因未自动引用。


To add a reference to your project: 要添加对项目的引用:

  1. Right-click the project node in the Solution Explorer . Solution Explorer右键单击项目节点。

    Solution Explorer

    (Image credit: another Stack Overflow question ) (图片来源: 另一个Stack Overflow问题

  2. Press Add Reference... . Add Reference...

  3. Go to the Browse tab and locate the file mentioned above. 转到“ Browse选项卡,找到上面提到的文件。

How to: Add or Remove References By Using the Add Reference Dialog Box 如何:使用“添加引用”对话框添加或删除引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM