tags:

views:

95

answers:

4

Hi

I need to open folder through windows explorer using C#. It is working fine untill there is comma in folder path. Here is an example:

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

The error is: The path '456' does not exist or it is not a directory.

Any solution please :)

+2  A: 

Try to surround the path with double-quotes:

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

Try adding double quotes around your path:

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

Side-note: you might find it easier to write paths using a verbatim string literal, to avoid having to escape the slashes:

System.Diagnostics.Process.Start("explorer.exe", @"""C:\folder\another-folder\123,456""");
Hosam Aly
It worked fine, thanks!
sturmgewehr
You would also need to do this if the path contained other special characters, such as space. So, to be safe, path strings should always be double quoted.
ShellShock
nice! :) [15chars]
st0le
A: 

Try escaping the file name:

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

Use the @ operator before the path string ...and then simply write down the path without any escape characters like backslashes etc. It makes the string verbatim.

System.Diagnostics.Process.Start(@"C:\myapp.exe"); // should work

mumtaz