I'm in a fix. I need to download a zip file from network location and then decompress it on local machine and use the files. The only constraint is that I cannot use any third party dll.
-
This looks like a duplicate of this question: http://stackoverflow.com/questions/836736/unzip-files-programmatically-in-net. You may want to check there for more answers. – Rich Aug 09 '10 at 06:44
-
2Why can't you use any third party library ? That's a stupid requirement... probably made by someone in management ;) – Thomas Levesque Aug 09 '10 at 07:51
-
It is actually a very important requirement since the lack of .NET Framework support for zips adds the complexity of adding another dll (and the security concern is true since if you look at Microsoft's due diligence with their code, it is much better than most) – Dinis Cruz Jul 04 '12 at 14:42
6 Answers
In .NET framework 4.5 now there is System.IO.Compression.ZipFile.ExtractToDirectory(String, String)
method.

- 9,672
- 5
- 36
- 57
-
-
-
25I like how the question specifically asked for a 4.0 solution and a 4.5 answer was selected – DontFretBrett Jun 26 '14 at 20:30
-
1
-
2Why is this the preferred answer, when the user has specified that it needs to work for .NET 4.0. – Krishnan Venkiteswaran Mar 06 '17 at 11:13
-
-
@Abbas, at the time the question was asked there was no .NET 4.5, .NET 4.0 was the latest version and you can interpret it as that, not as a specific version. As you can see above the answer on how to do that in .NET 4.5 was clearly useful to the OP. But you probably know better than OP what he meant and what is useful answer, right? – Ivan Ičin Oct 30 '20 at 21:43
I'm not sure if it's still available in VS2010, but in earlier versions J# was included in VS and J# includes the java.util.zip
class in the vjslib.dll, and since it's part of VS, it's not a third party DLL so you might be able to do it that way.
Here's a CodeProject article showing how to do this: Zip and Unzip from a C# program using J# runtime

- 54,199
- 15
- 94
- 116
-
-
Note that J# isn't shipped with .NET Framework anymore, although it is still shipped with VS2005-2015. This might still be a valid solution for some people. https://social.msdn.microsoft.com/Forums/office/en-US/627b5ca3-fac7-461f-9e3a-824fd2a5eb32/problem-with-vjslibdll?forum=netfxbcl – ErikusMaximus Nov 01 '17 at 20:57
There is no "good" way to do this. You could obviously implement the ZIP algorithm yourself using publicly available information on the ZIP file structure and classes such as DeflateStream (though even this may not work if it is not compressed using the DEFLATE algorithm). There is some information on possible alternatives in this blog post, but the short version is that you will either have to use a third-party library or re-write one yourself.
If this is a situation where you would be able to release the source code in a GPL'd manner, you could copy-paste the code from a project like SharpZipLib into your own, thereby sidestepping the requirement to use the DLL. Other than that, though, why can't you use third-party DLLs?

- 18,333
- 31
- 67
- 74
The .NET framework itself does not (currently) have official support for ZIP files. There are a couple of high-quality third-party free libraries available, and the J# runtime supports it, as others have noted.
I recommend the third-party solution, but if you absolutely can't do that, then there is one other trick: ZipPackage, which is part of WPF. It sort-of supports ZIP files (augmented with extra metadata), and works well enough for reading most ZIP files.

- 437,863
- 77
- 675
- 810
GZipStream is most commonly used for WCF data compression. Dont use that here.
You can try this ZIP library to compress into files:

- 4,086
- 3
- 27
- 38
-
2This does not appear to be a WCF question, and GZipStream isn't going to help with ZIP files, which usually use the DEFLATE algorithm. – Ryan M Aug 09 '10 at 06:56
-
-
SharpZipLib will fail with files compressed by a unix host system. For example when made on a MacOSX machine, using the internal zip compressor – Highmastdon Apr 24 '13 at 10:19
A quick google search turned this up. GZipStream Class MSDN Reference

- 2,911
- 1
- 17
- 24
-
5"...however, this class does not inherently provide functionality for adding files to or extracting files from .zip archives..." – Dan Byström Aug 09 '10 at 06:31