Search code examples
c#windowsexplorerprocessstartinfo

Starting Explorer with UNC Path Argument That Contains Comma Fails To Open Folder


Passing in a value with a comma in the UNC path (e.g. "\servername\Smith,John\Documents\") causes the following to start windows explorer but it opens the My Documents instead of the folder path. If I paste in the path into windows explorer's address bar, the folder opens appropriately.

public void OpenWindowsExplorer(string path) {
        var runExplorer = new ProcessStartInfo { FileName = "explorer.exe", Arguments = path };
        Process.Start(runExplorer);
    }

Any idea as to why this is happening/how to resolve the issue is greatly appreciated.


Solution

  • Put quotes around the path:

    public void OpenWindowsExplorer(string path) {
        path = string.Format("\"{0}\"", path);
        var runExplorer = new ProcessStartInfo { FileName = "explorer.exe",
                                                 Arguments = path };
        Process.Start(runExplorer);
    }