• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3205
  • Last Modified:

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

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);

  • 2
1 Solution
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 ?
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#"

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now