0

I have an app that queries a database for the location of a nested folder used for a task, and opens this folder (using the ProcessStartInfo class to launch explorer.exe and pass in the folder name as an argument).

This works fine except for a number of folders that contain commas (and unfortunately there are a load of them!)

Say, for a folder called C:\this,folder\, it tries to launch "folder". How can I get it to treat the comma as verbatim?

Sample code:

public void LaunchExplorer() {
        ProcessStartInfo explorer = new ProcessStartInfo();             

        string windir = Environment.GetEnvironmentVariable("WINDIR");
        System.Diagnostics.Process prc = new System.Diagnostics.Process();
        prc.StartInfo.FileName = windir + @"\explorer.exe ";
        prc.StartInfo.Arguments = @"c:\this,folder";
        prc.StartInfo.UseShellExecute = false;

        try                                       
        {                
            prc.Start();
        }

        catch
        {
            MessageBox.Show("cannot open folder " + prc.StartInfo.Arguments);
        }
}

2 Answers2

5

Have you tried enclosing the folder name in quotes, like this?

prc.StartInfo.Arguments = "\"c:\\this,folder\"";
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Jon
  • 428,835
  • 81
  • 738
  • 806
0
prc.StartInfo.Arguments = "\"c:\\this,folder\"";

will do the trick

Anders
  • 878
  • 1
  • 9
  • 20