If you want to decompress the file in asp.net application. this is for you.
I used two name spaces System.IO and System.IO.Compression
Button_Click event.
DecompressFile(Server.MapPath("~/Decompressed/FindEmai_onTextfile.zip"),Server.MapPath("~/Decompressed/FindEmai_onTextfile.txt"));
Here i just swap the filename so it may confuse so use some different path(Folder) or filename
Decompress Method
public static void DecompressFile(string sourceFileName, string destinationFileName) {
FileStream outStream;
FileStream inStream;
//Check if the source file exist.
if (File.Exists(sourceFileName)) {
//Read teh input file
inStream = File.OpenRead(sourceFileName);
//Check if the destination file exist else create once
outStream = File.Open(destinationFileName, FileMode.OpenOrCreate);
//Now create a byte array to hold the contents of the file
//Now increase the filecontent size more since the compressed file
//size will always be less then the actuak file.
byte[] fileContents = new byte[(inStream.Length * 100)];
//Read the file and decompress
GZipStream zipStream = new GZipStream(inStream, CompressionMode.Decompress, false);
//Read the contents to this byte array
int totalBytesRead = zipStream.Read(fileContents, 0, fileContents.Length);
outStream.Write(fileContents, 0, totalBytesRead);
//Now close all the streams.
zipStream.Close();
inStream.Close();
outStream.Close();
}
}
For more details, visit http://niksgaur.blogspot.com/2009/08/decompress-file-using-aspnet.html
|
No responses found. Be the first to respond and make money from revenue sharing program.
|