2016-04-11 20 views
-1

Aşağıdaki C# kodunda .zip dosyasının konumunu files parametresine iletmem gerekiyor.7-Zip hatası alıyorum - Boşluklu dosya adlarını Process.Start() yöntemiyle iletilemiyor.

Dosya adı boşluk İÇERMEZ, her şey yolunda çalışıyor. Ancak, dosya adı boşluk içeriyorsa, aşağıdaki hatayı atıyor.

kodum olan arşiv Aşağıda

bulunamıyor: Biri bana önermek misiniz nasıl bu sorunu çözebilir?

 static void UnzipToFolder(string zipPath, string extractPath, string[] files) 
    { 
     string zipLocation = ConfigurationManager.AppSettings["zipLocation"];    

     foreach (string file in files) 
     { 
      string sourceFileName = string.Empty; 
      string destinationPath = string.Empty; 
      var name = Path.GetFileNameWithoutExtension(file); 
      sourceFileName = Path.Combine(zipPath, file); 
      destinationPath = Path.Combine(extractPath, name); 

      var processStartInfo = new ProcessStartInfo(); 
      processStartInfo.FileName = zipLocation; 
      processStartInfo.Arguments = @"x " + sourceFileName + " -o" + destinationPath; 
      processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
      var process = Process.Start(processStartInfo); 
      process.WaitForExit(); 
     } 
    } 
+1

Teşekkür bile bana nedenini söylemeden. –

cevap

3

dosya yolları etrafında tırnak ekleyin:

processStartInfo.Arguments = "x \"" + sourceFileName + "\" -o \"" + destinationPath + "\""; 

Veya (C# 6 ile birlikte) okunabilmesi için

: Aşağı oy için birilerine

processStartInfo.Arguments = $"x \"{sourceFileName}\" -o \"{destinationPath}\"";