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