Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

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.

I tried using the following line:

System.Diagnostics.Process.Start("Explorer");

This will popup the Windows Explorer window, however, it always seems to open up by default in "My Documents" folder.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
339 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here you go,

string fileToSelect = @"C:emp.img";
string args = string.Format("/Select, "{0}"", fileToSelect);

ProcessStartInfo pfi = new ProcessStartInfo("Explorer.exe", args);
System.Diagnostics.Process.Start(pfi);

Note: Adding " before and after the {0} parameter enables the fileToSelect string to contain spaces (i.e. "C:My Documents").

From this Thread:
Programmatically select multiple files in windows explorer

Cheers,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...