Normally I don't like to require third-party libraries. I don't know what tools you have loaded and don't want to assume you can load new tools without creating conflicts. If third-party tools get out of synch, it can also be hard to upgrade appropriately to get them all working again.
However, this tool seems worth adding to your toolkit. The .NET Framework comes with a System.IO.Compression.GZipStream class that lets you compress and uncompress files. Unfortunately it works only with GZip files (with a .gz extension) not regular .zip files. You can open these files with many other third-party tools but the Windows operating system doesn't let you browse them the way it can Zip files. (I don't see the logic in providing a way to make compressed files that the operating system can't read. Perhaps it's a licensing issue.)
The DotNetZip library, which is free, provides .NET managed classes that you can use from C# to compress and decompress true Zip files. This example only shows a couple of the library's features.
Enter a file name and the path you want it to have in the archive. (Use \ to place the file in the archive's root.) Enter the archive's name and click Add to Archive to add the file to the archive. You can then open the archive with Windows Explorer and see what's inside it.
Enter an Extract To Path and click Extract Archive to extract all of the files in the archive into the path.
The following code shows how the program adds the file to the archive. The code in the using block is all there is to actually adding the file to the archive.
|