Last active
October 15, 2021 22:35
-
-
Save CheetahChrome/5cf7b831c26f66a791f1276feb1e946a to your computer and use it in GitHub Desktop.
Get Selected file in Explorer and Put it on the Clipboard in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add reference Com -> `Microsoft Shell Controls` and `Microsoft Internet Controls` | |
// and System.Windows & PresentationCore for Clipboard | |
foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows()) | |
{ | |
var filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower(); | |
if (filename.ToLowerInvariant() == "explorer") | |
{ | |
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems(); | |
foreach (Shell32.FolderItem item in items) | |
{ | |
Clipboard.SetText(item.Path); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment