Warning The Windows OS can cause problems here if you are not an administrator on your PC.
static void Main()
string sourceName = "ExampleText.txt";
string targetName = "Example.gz";
// Initialize process information.
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "7za.exe";
// Use 7-zip.
// Specify a=archive and -tgzip=gzip
// and then target file in quotes followed by source file in quotes.
p.Arguments = "a -tgzip \"" + targetName + "\" \"" +
sourceName + "\" -mx=9";
p.WindowStyle = ProcessWindowStyle.Hidden;
// Start process and wait for it to exit.Process x = Process.Start(p);
Verify results. Open the bin\Debug or bin\Release folder in your project's directory, and you should see the compressed file. Extract that file with 7-Zip, and it will have the same data.
Tip First make sure all the files are being copied and the Arguments syntax is correct. The quotes in the syntax are important.