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

发布于 2024-08-19 13:40:46 字数 457 浏览 15 评论 0原文

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

Process ExplorerWindowProcess = new Process();

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

ExplorerWindowProcess.Start();

...但这会使用 Windows 资源管理器中的默认应用程序打开文件(在我的例子中是 XML 文件),这是我非常不想要的。我知道可用于 Eclipse 的 Aptana 工具允许您在 Eclipse 项目浏览器中选择文件并完全按照我的需要在资源管理器中显示该文件,但我需要一种方法在我的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画▽骨i 2024-08-26 13:40:46

资源管理器命令行参数
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.

您还需要在周围加上引号文件名如下:

startInfo.FileName = "explorer.exe";
startInfo.Arguments = "/select,\"" + ConfigFile.File.FullName + "\"";

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 + "\"";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文