C#逐字符似乎不适用于.startinfo.arguments?

问题描述:

我有一个应用程序,我可以从多个MSI(相同的msi,不同的版本)中选择一个目录,我将能够安装或从这个应用程序卸载。C#逐字符似乎不适用于.startinfo.arguments?

我拉在微星的,完整的全路径的列表,

string MSILocation = @"C:\test\"; 
string[] MSIFiles = Directory.GetFiles(MSILocation, "*.MSI", SearchOption.TopDirectoryOnly); 

在这里,我填充一个列表视图,和当一个被选中我打的安装按钮。 但是,当我通过我的安装代码,逐字似乎搞砸了。

string MSIname = lboMSIList.SelectedItem.ToString(); 
Process p = new Process(); 
p.StartInfo.FileName = "MSIEXEC.EXE"; 
p.StartInfo.Arguments = @"/i " + MSIname; 
p.Start(); 

即使列表视图显示了单个文件/最后的结果永远是双/

某处有其失去的文本字符串。

如果我更改代码并运行.FileName = @“msiexec.exe/i C:\ test \ test1.msi”它工作得很好,但我需要能够从列表中选择文件名。

任何想法?

+0

是否有出来”''\\在调试视图?这只是调试器。 –

string MSILocation = @"C:\test\"; 
string[] MSIFiles = Directory.GetFiles(MSILocation, "*.*", SearchOption.TopDirectoryOnly).Select(f => Path.GetFileName(f)).ToArray(); 

使用上述MSIFiles阵列的文件名来填充ListView

使用Path.combine如下

string MSILocation = @"C:\test\"; 
string MSIname = lboMSIList.SelectedItem.ToString(); 
Process p = new Process(); 
p.StartInfo.FileName = "MSIEXEC.EXE"; 
p.StartInfo.Arguments = string.Format(
"{0} {1}", @"/i",Path.Combine(MSILocation , MSIname); 
p.Start(); 
+0

Path.combine似乎修复它。令人沮丧的问题,感谢您的帮助 – LimeyTX