2014-05-10 59 views
3

我想靜默提取.rar檔案。 .Net在IO.Compression中沒有任何Rar類,所以我想使用cmd(比外部dll更好)。它提取,但不是以靜音模式。我究竟做錯了什麼?Unrar在C#中的檔案文件

const string source = "D:\\22.rar"; 
string destinationFolder = source.Remove(source.LastIndexOf('.')); 
string arguments = string.Format(@"x -s ""{0}"" *.* ""{1}\""", source, destinationFolder); 
Process.Start("winrar", arguments); 

回答

6

我使用這段代碼自己(添加代碼):

const string source = "D:\\22.rar"; 
string destinationFolder = source.Remove(source.LastIndexOf('.')); 
System.Diagnostics.Process p = new System.Diagnostics.Process(); 
p.StartInfo.CreateNoWindow = true; 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.FileName = "\"C:\\Program Files\\WinRAR\\winrar.exe\""; 
p.StartInfo.Arguments = string.Format(@"x -s ""{0}"" *.* ""{1}\""", source, destinationFolder); 
p.Start(); 
p.WaitForExit(); 

這將在後臺啓動WinRAR程序,一旦該文件已完成非RAR-控制返回給你ING。

希望可以幫助

1

或者,你可以用你的應用程序調用的和unRAR工具,通過WinRAR的的開發者(official download)開發的小型可執行嵌入。

此實用程序是免費的,因此您的用戶將不需要擁有WinRAR許可證即可使用您的應用程序。 :)它可以用相同的方式執行txtechhelp描述。