Decompress .gz file in C# ASP.NET

//Following Code will help u to decompress

using ICSharpCode.SharpZipLib.GZip;

Stream s = new GZipInputStream(File.OpenRead(@"C:\Sample.txt.gz"));
FileStream fs = File.Create(@"C:\Sample.txt");
int size = 2048;
byte[] writeData = new byte[2048];
while (true)
{
size = s.Read(writeData, 0, size);
if (size > 0)
{
fs.Write(writeData, 0, size);
}
else
{
break;
}
}
s.Close();
fs.Close();

///Following code will use to compress the file to.gz
Stream s = new GZipOutputStream(File.Create(@"C:\Sample.txt.gz"));
FileStream fs = File.OpenRead(@"C:\Sample.txt");
byte[] writeData = new byte[fs.Length];
fs.Read(writeData, 0, (int)fs.Length);
s.Write(writeData, 0, writeData.Length);
s.Close();
fs.Close();

//Download the dll from here
http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx

Comments

Popular posts from this blog

To Move items from one ListBox to another Listbox

Receive Json Web response in C#