I can easily get Explorer to open up and select a file using the following :
string argument = @"/select, " + filePath;
System.Diagnostics.Process.Start("explorer.exe", argument);
However when I come to opening up the next file, I will get a new instance of explorer. This could result in our users opening having hundreds of explorers open by the end of an intensive day.
How can I get it to reuse an already open explorer instance to select the file I want?
Visual Studio can do this when you right click on a tab and select Open containing folder… providing explorer is already opened at the same directory. How has it been able to do this?
How about embedding the Explorer window into your application by using the
ExplorerBrowserobject? That way, you can just keep reusing the window by callingIExplorerBrowser::BrowseToObjecton a different folder when you want to show a different folder.Trying to renavigate an existing Explorer window is problematic because you don’t know what the user did with that window while you weren’t looking. Maybe they used the Folder pane to go to some other folder, and then boom you just ripped that folder out from under them and sent it somewhere else. Or maybe they closed it! Opening a new Explorer window is a fire-and-forget type of thing. If you want to retain control of the window, then you need to exercise more explicit control (e.g. via
ExplorerBrowserabove).