2010-09-20 142 views
5

我需要通过使用C#的Windows资源管理器打开文件夹。 它工作正常,直到文件夹路径中有逗号。这里是一个例子:打开其中包含逗号文件夹的路径

System.Diagnostics.Process.Start("explorer.exe", "C:\\folder\\another-folder\\123,456"); 

错误是:路径'456'不存在或它不是一个目录。

任何解决方案,请:)

+1

你尝试转义它吗? – st0le 2010-09-20 08:03:41

+0

@ st0le:没有什么可逃脱的;它只需要被双引号包围。 – 2010-09-21 12:35:11

回答

2

尝试用双引号的路径:

System.Diagnostics.Process.Start("explorer.exe", "\"C:\\folder\\another-folder\\123,456\""); 
13

尝试添加在你的路径双引号:

System.Diagnostics.Process.Start("explorer.exe", "\"C:\\folder\\another-folder\\123,456\""); 

侧面说明:您可能会发现使用逐字字符串文字编写路径更容易,以避免必须避开斜线:

System.Diagnostics.Process.Start("explorer.exe", @"""C:\folder\another-folder\123,456"""); 
+0

它工作正常,谢谢! – sturmgewehr 2010-09-20 08:05:40

+2

如果路径包含其他特殊字符(如空格),则还需要执行此操作。所以,为了安全起见,路径字符串应该总是用双引号。 – Polyfun 2010-09-20 08:24:00

+0

不错! :) [15chars] – st0le 2010-09-21 12:49:37

0

尝试逃跑的文件名:

System.Diagnostics.Process.Start("explorer.exe", "\"C:\\folder\\another-folder\\123,456\""); 
0

路径字符串之前使用@操作......然后简单地写下来的路径没有任何转义字符像反斜杠等,这使得该字符串一字不差。 System.Diagnostics.Process.Start(@“C:\ myapp.exe”); //应该可以工作

相关问题