Forked from CheetahChrome/GetSelectedFileInExplorerAddToClipboard.cs
Created
October 15, 2021 22:35
-
-
Save tshego3/f8ddc4e5ccb801cd100fc79a7c302f0e 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 hidden or 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