In Windows, either on the desktop or in Windows Explorer, I want to detect the moment when a file or folder is selected (highlighted). When that happens, I want to display a message box showing the file or folder's full name.
If there are multiple items selected, I want to display all of them.
Note that my solution must be written in C#.
Take a look at this example to get the mouse click or selected events:
https://stackoverflow.com/questions/7222749/i-created-a-program-to-hide-desktop-icons-on-double-click-of-desktop-but-would-o
Join that with the following code, Remember to add reference to SHDocVW.dll and Shell32.dll this will return all the selected items and folders paths in every explorer.
public void GetListOfSelectedFilesAndFolderOfWindowsExplorer()
{
string filename;
ArrayList selected = new ArrayList();
var shell = new Shell32.Shell();
//For each explorer
foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
{
filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
if (filename.ToLowerInvariant() == "explorer")
{
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
foreach (Shell32.FolderItem item in items)
{
MessageBox.Show(item.Path.ToString());
selected.Add(item.Path);
}
}
}
}
Just adding somethings to Renier's answer:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With