【问题标题】:C# Verbatim doesn't seem to work with .startinfo.arguments?C# Verbatim 似乎不适用于 .startinfo.arguments?
【发布时间】:2011-11-10 18:37:02
【问题描述】:

我有一个应用程序,我可以使用该应用程序从目录中的多个 MSI(相同的 msi,不同版本)中进行选择,并且我将能够从该应用程序安装或卸载。

我拉入了 MSI 的列表,包含完整路径,

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" 它工作得很好,但我需要能够选择来自文件名列表。

有什么想法吗?

【问题讨论】:

  • 在调试器视图中使用 `\` 是否可以解决?这只是调试器。

标签: c# wpf windows-installer verbatim


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

使用上面的MSIFiles 文件名数组来填充列表视图

如下使用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(); 

【讨论】:

  • Path.combine 似乎可以修复它。令人沮丧的问题,感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2020-04-04
  • 2023-04-06
  • 2017-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多