C# code to compress a file

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 255
The below code will do so

public static void CompressFile(string filePath)
{
FileInfo info = new FileInfo(filePath);

using (FileStream originalFileStream = info.OpenRead())
{

using (FileStream compressedFileStream = File.Create(filePath + ".gz"))
{
using (GZipStream compressionStream = new GZipStream(compressedFileStream,
CompressionMode.Compress))
{
originalFileStream.CopyTo(compressionStream);

}
}
}
}

Comments or Responses

Login to post response