打开文件夹并使用WPF突出显示特定文件

时间:2023-01-17 08:35:47

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

有没有办法启动资源管理器窗口并使用WPF突出显示该文件夹中的文件?我已经尝试过以下方法:

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.

...但是在Windows资源管理器中使用默认应用程序打开文件(在我的情况下是一个XML文件),我非常不想要。我知道可用于Eclipse的Aptana工具允许您在Eclipse项目浏览器中选择一个文件并在Explorer中完全按照我的意愿显示该文件,但我需要一种方法在我的WPF应用程序中实现它。

1 个解决方案

#1


30  

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

Explorer命令行参数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 + "\"";

#1


30  

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

Explorer命令行参数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 + "\"";