Search code examples
c#.net-3.5winzip

Call Winzip32.exe with parameter with c#


I want zip folder through my console application that's why I used something like

public void DoWinzip(string zipName, string password, string folderName)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "C:\\Program Files\\WinZip\\winzip32.exe";
            startInfo.Arguments = string.Format("-min -eZ {0} {1}", zipName, folderName);

            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                }
            }
            catch(Exception ex)
            {
                // Log error.
            }

        }

But this will give me error like winzip parameters validation error. Where I do mistake?

Update

I spell wrong on -eZ actually it may -ex etc... But another problem is that winzip open up own windows. I write for it -min however it opened.


Solution

  • You can avoid to open up windows by using ProcessStartInfo.WindowStyle property

    Try this:

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "C:\\Program Files\\WinZip\\winzip32.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;