C
C#13mo ago
Nemesis

❔ Process.Start doesn't open directory

I am looking for a generalized way of opening directories through C# application. Most of the stackoverflow answers, such as this: https://stackoverflow.com/questions/1746079/how-can-i-open-windows-explorer-to-a-certain-directory-from-within-a-wpf-app/30939461#30939461, say Process.Start(<directory>) should work. But I get exception:
System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'file:///C:/dev/directory' with working directory '<workingdirectory>'. The system cannot find the file specified.'
I am able to open the directory by Process.Start("explorer", "C:/dev/directory"). So, why is the other way not working? Is the answer for an older version of C# or am I doing something wrong?
Stack Overflow
How can I open Windows Explorer to a certain directory from within ...
In a WPF application, when a user clicks on a button I want to open the Windows explorer to a certain directory, how do I do that? I would expect something like this: Windows.OpenExplorer("c:\tes...
3 Replies
reflectronic
reflectronic13mo ago
that answer is only for .NET 4.x, it is wrong for newer versions of .NET you would need to use
var psi = new ProcessStartInfo("C:/dev/directory") { UseShellExecute = true };
Process.Start(psi);
var psi = new ProcessStartInfo("C:/dev/directory") { UseShellExecute = true };
Process.Start(psi);
since the default value is false in newer versions of .NET or, you can use explorer.exe directly as you did, and that's also fine
Petris
Petris13mo ago
also, i don;t think file:///C:/dev/directory is a valid path for it
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server