Solved 2.0 c# compress/decompress files into zip format

Posted on 2006-05-18
Last Modified: 2013-11-25
how does one in 2.0 c# compress/decompress files into zip format and back out of zip format?

1. take a file such as C:\compressiontests\myfile.txt
   this could be a file from any source, possibly one that a user uploads
2. zip it as and store in C:\compressiontests\com\
3. unzip it as myfile.txt and store in C:\compressiontests\decom\myfile.txt

string myFile;
myFile = @"C:\compressiontests\myfile.txt";

//get filestream
FileStream filestream = new FileStream(myFile, FileMode.Create); //don't want to recreate it just get the file in myFile
//compress file
GZipStream compressStream = new GZipStream(filestream, CompressionMode.Compress);
//write with compressed file to location
StreamWriter w = new StreamWriter(@"C:\compressiontests\com\" + compressStream + ".zip");
// this is what I get = not the actual file name
//flush & close

//now decompress/unzip the file
FileStream dfilestream = new FileStream(@"C:\compressiontests\com\" + w, FileMode.Open);
//get = can't find file
GZipStream decompressStream = new GZipStream(dfilestream, CompressionMode.Decompress);
StreamReader r = new StreamReader(decompressStream);

Question by:fwsteal
    LVL 3

    Expert Comment

    I believe that .NET framework 2.0 only supports raw/deflate compression for streams and does not support the Zip file format.

    have you looked at using something like the free C# zip library from ?
    LVL 3

    Accepted Solution

    opps - looks like there might be a way to do it....
    "Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now