Question

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.

Was it helpful?

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top