[Code] Show a file in Explorer
I've noticed that some of my favorite programs have options to open the currently selected file in Explorer. I don't just mean that they open the right folder, but that they preselect the right file for you.
Visual Studio 2005 does it when you select "Open Containing Folder in the File tabs:
Firefox has it in the downloaded file dialog, and TimeSnapper shows it as an option in image browse mode.
It's not hard to add to your programs, too:
The code's reasonably simple once you've got the right arguments to pass to Explorer:
private static void ShowFileInExplorer(string filePath)
{
if (!File.Exists(filePath))
throw new FileNotFoundException("File not found", filePath);
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = "explorer";
processStartInfo.UseShellExecute = true;
processStartInfo.WindowStyle = ProcessWindowStyle.Normal;
processStartInfo.Arguments =
string.Format("/e,/select,\"{0}\"", filePath);
Process.Start(processStartInfo);
}