[Sample Of Nov. 07] How to compress files into a single .gz file for download in ASP.NET(VS2010)


Sample : https://code.msdn.microsoft.com//How-to-compress-files-into-175143d0

Many people seem to think, incorrectly, that the classes in the System.IO.Compression namespace, like GZipStream or DeflateStream, can create or read zip files. Not true. The System.IO.Compression namespace, available starting with .NET v2.0 for the desktop Framework and v3.5 for the Compact Framework, includes base class libraries supporting compression within streams – both the Deflate and Gzip formats are supported. But these classes are not directly useful for creating compressed ZIP archives. GZIP is not ZIP. Deflate is not ZIP. The GZipStream in System.IO.Compression is able to read and write GZIP streams, but that is not the same as reading or writing a zip file. Also, these classes deliver poor compression in practice, especially with binary data, or previously-compressed data. The sample demonstrates how to compress files into a single .gz file for download in ASP.NET using System.IO.Packaging. However a better approach is to use dotnetzip library available in codeplex http://dotnetzip.codeplex.com/ One cavet of using the ZipPackage to create Zips is that Packages contain a content type manifest named “[Content_Types].xml”.



You can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.

Skip to main content