[Last Call] Learn how to a build a cloud-first strategyRegister Now


asp.net 2.0 c# compress/decompress files into zip format

Posted on 2006-05-18
Medium Priority
Last Modified: 2013-11-25
how does one in asp.net 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 myfile.zip and store in C:\compressiontests\com\myfile.zip
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 = System.IO.Compression.GZipStream.zip not the actual file name myfile.zip
//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
  • 2

Expert Comment

ID: 16723000
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 http://www.sharpziplib.org ?

Accepted Solution

rstrader earned 2000 total points
ID: 16723013
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#"


Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

831 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