I would like to open a folder using .NET and it seems like as if Process.Start is the way to go: Open a folder using Process.Start.
I already read How to securely use Process.Start? but it deals with user input and was answered almost six years ago, it might be outdated.
I have a certain path like the following which is not based on any user input:
- C:\Users\cow
- C:\Users\cow\
What I already learned is to check whether the path is acually a folder path i.e. ends with a backslash. Another workaorund would be to specify "explorer.exe" directly. I decided to do both and came up with the following:
var path = @"C:\Users\cow";
if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
{ //To avoid things like C:\Users\cow.exe
path += Path.DirectorySeparatorChar;
}
Process.Start("explorer.exe", path);
What else should I take in consideration?