<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {

        // Read the file we are going to compress into a FileStream
        string filename = Server.MapPath("TextFile.txt");

        System.IO.FileStream infile = System.IO.File.OpenRead(filename);
        byte[] buffer = new byte[infile.Length];
        infile.Read(buffer, 0, buffer.Length);
        infile.Close();

        // Create the output file
        System.IO.FileStream outfile = 
            System.IO.File.Create(System.IO.Path.ChangeExtension(filename, "zip"));

        // Compress the input stream and write it to the output FileStream
        System.IO.Compression.GZipStream gzipStream = 
            new System.IO.Compression.GZipStream(outfile, 
                System.IO.Compression.CompressionMode.Compress);
        gzipStream.Write(buffer, 0, buffer.Length);
        gzipStream.Close();
    }
</script>