I want to open the folder where a file had been just saved and select the file, for that I use this little code:
var psi = new ProcessStartInfo("Explorer.exe", "/select," + dlg.FileName);
Process.Start(psi);
It works perfectly.
I need to put this code in several places so I decided to create a method, there is also a condition in this method:
private static void OpenFolderAndSelectMyFile(string fileName)
{
if (MySettings.Default.openFolder == true)
{
var psi = new ProcessStartInfo("Explorer.exe", "/select," + fileName);
psi.WindowStyle = ProcessWindowStyle.Maximized;
Process.Start(psi);
}
}
This doesn't work as expected: this opens the parent folder (of the folder containing my file). It also selects the folder.
Why this difference in behavior and how to solve it?
The only way for this to occur, is fileName
isn't what it was in your original code. The code is exactly the same, and would work as expected, if fileName
was in fact what it was in the original code location.
It's likely that fileName
is now actually the full path to the folder rather than the full path to the file including the file name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With