示例代码:
string filepath = Server.MapPath("Textfile.txt");
FileStream infile = File.OpenRead(filepath);
byte[] buffer = new byte[infile.Length];
infile.Read(buffer, 0, buffer.Length);
infile.Close();
FileStream outfile=File.Create(Path.ChangeExtension(filepath,"zip"));
GZipStream gzipstream=new GZipStream(outfile,CompressionMode.Compress);
gzipstream.Write(buffer,0,buffer.Length);
gzipstream.Close();