2012-02-25 139 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 =無壓縮