Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a folder and highlight a particular file with WPF

Is there a way to launch an Explorer window and highlight a file in that folder with WPF ? I've already tried the following :

Process ExplorerWindowProcess = new Process();

ExplorerWindowProcess.StartInfo.FileName = "explorer.exe";
ExplorerWindowProcess.StartInfo.Arguments = ConfigFile.File.FullName;

ExplorerWindowProcess.Start();

... but that opens the file (in my case an XML file) with the default application in Windows Explorer, which I very much don't want. I know that the Aptana tools available for Eclipse allow you the ability to select a file in the Eclipse project browser and show the file in Explorer exactly as I want, but I need a way to implement this in my WPF app.

like image 460
Alex Marshall Avatar asked Jan 30 '10 23:01

Alex Marshall


1 Answers

Explorer Command Line Arguments
http://support.microsoft.com/kb/152457

Explorer [/n] [/e] [(,)/root,<object>] [/select,<object>]

/n                Opens a new single-pane window for the default
                  selection. This is usually the root of the drive Windows
                  is installed on. If the window is already open, a
                  duplicate opens.

/e                Opens Windows Explorer in its default view.

/root,<object>    Opens a window view of the specified object.

/select,<object>  Opens a window view with the specified folder, file or
                  application selected.

You will also want to put quotes around the filename like so:

startInfo.FileName = "explorer.exe";
startInfo.Arguments = "/select,\"" + ConfigFile.File.FullName + "\"";
like image 120
Josh Avatar answered Oct 31 '22 02:10

Josh