1

I'm trying to compile this simple code in my C# WinForms project in VS 2010:

using System.IO;
using System.IO.Compression;

string zipPath = @"c:\example\start.zip";
string extractPath = @"c:\example\extract";

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
    foreach (ZipArchiveEntry entry in archive.Entries)
    {
        if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
        {
            entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
        }
    }
}

The description for the ZipFile Class tells me that I need to add System.IO.Compression.FileSystem assembly. Sorry for this question, but where the heck is it? Does it come as a DLL? It is not in the list of the .NET references, and I know for sure that I have .NET Framework v.4.5 installed.

EDIT: Whoever wants to include a simple Zip archive support in your VS 2010 project, I found this project that compiles right into your own project. Very clean and simple.

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 3
    You need to use VS 2012 to use .NET 4.5. VS 2010 does not support 4.5, and that assembly is only available in 4.5. – Tim Nov 02 '13 at 08:08
  • 1
    @Tim: Hmm. So Microsoft wants us to buy VS 2012 to use Zip archiving capabilities. Did I get it right? – c00000fd Nov 02 '13 at 08:10
  • @Tim : Exactly Tim. we should use .NET 4.5 to get Zip capabilities. – Sudhakar Tillapudi Nov 02 '13 at 08:12
  • I'll skip the politics, but yes, you must use Visual Studio 2012 for those specific classes. http://stackoverflow.com/questions/12390175/targeting-net-framework-4-5-via-visual-studio-2010. You can use GZipStream to zip and unzip individual files. You can also use SharipZipLib if you can live with the GNU license: http://www.icsharpcode.net/opensource/sharpziplib/. We also had excellent luck with the Chilkat Zip library, but that isn't free: http://www.chilkatsoft.com/zip-dotnet.asp. – bopapa_1979 Nov 02 '13 at 08:13
  • @COOOOOfd : please upgrade to vs2012 – Sudhakar Tillapudi Nov 02 '13 at 08:13

3 Answers3

5

You may have the .NET 4.5 framework installed, but you need to have VS 2012 to use components from it when developing programs in 4.5.

VS 2010 supports .NET 2.0, 3.0, 3.5 and 4.0, but not 4.5.

VS 2012 supports all of the above plus .NET 4.5. The ZipFile Class is new in 4.5, there are no earlier versions of it (according to the MSDN link, at least).

If you don't want to buy VS 2012, you can check into the Visual Studio Express 2012 Products, which are free.

Tim
  • 28,212
  • 8
  • 63
  • 76
  • 1
    Wow. That is totally ridiculous. I was not thinking of upgrading the entire IDE just to include unzipping functionality to this project :) Any other way to unzip a file without upgrading to VS 2012? :) – c00000fd Nov 02 '13 at 08:15
  • no there isn't. it has nothing to do with MS wanting you to buy the new products. you are the one needing to use the assembly which was developed for .NET 4.5 and later....the only other alternative is to NOT use it and use something like ziplib or csharpzip or something like that. its been a while since I used it myself. – Ahmed ilyas Nov 02 '13 at 08:18
  • A quick Google reveals [DotNetZip](http://archive.msdn.microsoft.com/DotNetZip), which might help. There are probably others as well. – Tim Nov 02 '13 at 08:20
  • a little respect please. it all had to do with licensing and other politics. for the "average" developer, they wont get it but there is ALOT to it for such products. so my advise is, either get VS2012/2013 and use the facility you are after or... don't and use something else. – Ahmed ilyas Nov 02 '13 at 08:21
  • @Tim: Do you know if `DotNetZip` comes with a 3rd party dll dependency? – c00000fd Nov 02 '13 at 08:24
  • @c00000fd: According to the [DotNetZip Library](http://dotnetzip.codeplex.com/) page on Codeplex, "DotNetZip is packaged as a single DLL, about 400k in size. It has no third-party dependencies." – Tim Nov 02 '13 at 08:27
  • @Tim: Thanks. It's not gonna work. I can't "spawn" any new dlls. Will have to keep looking... Is there something that compiles into my project? (Same exe.) – c00000fd Nov 02 '13 at 08:28
2

You can use Visual Studio 2010 and it does support it, provided your OS supports .NET 4.5.
I know this because I use Visual Studio 2010 on Windows 8.

Right click on your solution to add a reference (as you do). When the dialog box shows, select browse, then navigate to the following folder:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5

You will find it there.

I had the same issue a while back.

Hope this helps.

Community
  • 1
  • 1
0

https://learn.microsoft.com/en-us/visualstudio/ide/how-to-add-or-remove-references-by-using-the-reference-manager?view=vs-2019

"In Solution Explorer, right-click on the References or Dependencies node and choose Add Reference. You can also right-click on the project node and select Add > Reference.

Reference Manager opens and lists the available references by group.

Specify the references to add, and then select OK."

In this case, search for "System.IO.Compression.FileSystem" and check the checkbox. That's all.