2012-02-25 135 views
0

参数我想通过这就是为什么我用类似呼叫Winzip32.exe用C#

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. 
      } 

     } 

但是,这会给我喜欢WinZip的参数验证错误,错误我的控制台应用程序的zip文件夹中。我错在哪里?

Update 

我拼写错了-eZ其实可能-ex等......但另一个问题是winzip打开自己的窗口。我为它写了 - 但是它打开了。

+1

为什么不用SharpZipLib(http://www.icsharpcode.net/opensource/sharpziplib/)?然后你完全控制了压缩过程。 – 2012-02-25 13:41:18

+0

我这样做没问题,但它提供了比WinZip更大的MB大小的zip文件 – 2012-02-25 13:44:28

回答

0

你能避免通过打开窗口ProcessStartInfo.Windo wStyle财产

试试这个:

ProcessStartInfo startInfo = new ProcessStartInfo(); 
startInfo.FileName = "C:\\Program Files\\WinZip\\winzip32.exe"; 
startInfo.WindowStyle = ProcessWindowStyle.Hidden; 
0
http://www.rondebruin.nl/parameters.htm

- >看,我会想到的代码是:

startInfo.Arguments =的String.Format( “ - ∈{0,1} {1}”,zipName,FOLDERNAME);

+0

也可以在设置它们之后尝试调试startInfo.Arguments,以确保实际传递所需的输入。 – 2012-02-25 13:48:46

1

也许你正在用空格传递路径(在zipNamefolderName参数中),而不用双引号括起来。

0

什么是-eZ?我认为这是你的问题

我认为,以下是决定压缩方法的唯一选择。

-ex =额外

-en =正常

-ef =快速

-es =超快

-e0 =无压缩