fwsteal
asked on
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\my file.zip
3. unzip it as myfile.txt and store in C:\compressiontests\decom\ myfile.txt
code:
string myFile;
myFile = @"C:\compressiontests\myfi le.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:\compress iontests\c om\" + compressStream + ".zip");
// this is what I get = System.IO.Compression.GZip Stream.zip not the actual file name myfile.zip
//flush & close
w.Flush();
w.Close();
filestream.Close();
//now decompress/unzip the file
FileStream dfilestream = new FileStream(@"C:\compressio ntests\com \" + w, FileMode.Open);
//get = can't find file
GZipStream decompressStream = new GZipStream(dfilestream, CompressionMode.Decompress );
StreamReader r = new StreamReader(decompressStr eam);
1. take a file such as C:\compressiontests\myfile
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\my
3. unzip it as myfile.txt and store in C:\compressiontests\decom\
code:
string myFile;
myFile = @"C:\compressiontests\myfi
//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:\compress
// this is what I get = System.IO.Compression.GZip
//flush & close
w.Flush();
w.Close();
filestream.Close();
//now decompress/unzip the file
FileStream dfilestream = new FileStream(@"C:\compressio
//get = can't find file
GZipStream decompressStream = new GZipStream(dfilestream, CompressionMode.Decompress
StreamReader r = new StreamReader(decompressStr
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
have you looked at using something like the free C# zip library from http://www.sharpziplib.org ?