我有有一个选项,以显示在该文件所在的文件夹中选择的文件的应用程序。我的问题是,我怎么做到这一点?
I have an application which has an option to show the selected file in the folder in which the file resides. My question is, how do I achieve this?
要澄清一下,如果我的节目的用户选择了Test.txt的文件,然后我想在Windows资源管理器窗口弹出,并突出显示用户选择的文件。你可以看到的LimeWire和uTorrent的类似行为。如果您选择在任一这些方案的文件,然后选择在文件夹,它会弹出该文件在Windows资源管理器窗口中高亮显示和选择。我试图复制这种行为。
To clarify, if a user in my program selected the "Test.txt" file, then I want a Windows Explorer window to pop up and highlight the file the user selected. You can see similar behavior in LimeWire and uTorrent. If you select a file in either of those programs and choose "Show in Folder", it pops up a Windows Explorer window with the file highlighted and selected. I am trying to duplicate this behavior.
我试着用下面的一行:
System.Diagnostics.Process.Start("Explorer");
这将弹出Windows的资源管理器窗口,但是,它似乎总是默认在我的文档文件夹中打开。
This will popup the Windows Explorer window, however, it always seems to open up by default in "My Documents" folder.
在这里,你走了,
string fileToSelect = @"C:\temp.img";
string args = string.Format("/Select, \"{0}\"", fileToSelect);
ProcessStartInfo pfi = new ProcessStartInfo("Explorer.exe", args);
System.Diagnostics.Process.Start(pfi);
注意:添加 \
的在和在的的 {0}
参数启用 fileToSelect
字符串包含空格(如C:\我的文档)。
Note: Adding \"
before and after the {0}
parameter enables the fileToSelect
string to contain spaces (i.e. "C:\My Documents").
从这个主题: 编程方式在Windows资源管理器
From this Thread: Programatically select multiple files in windows explorer
干杯,