I am using SHCreateItemFromParsingName
to turn a path into a IShellItem
:
IShellItem ParseName(String path)
{
IShellItem shellItem;
HRESULT hr = SHCreateItemFromParsingName(path, null, IShellItem, out shellItem);
if (Failed(hr))
throw new ECOMException(hr);
return shellItem;
}
Note: A
IShellItem
was introduced around 2006 to provide a handy wrapper around the Windows 95-eraIShellFolder
+pidl
constructs. You can even ask aIShellItem
to cough up it's underlyingIShellFolder
andpidl
with theIParentAndItem.GetParentAndItem
interface and method.
Different things have different display names
I can get ahold of some well-known locations in the shell namespace, and see their absolute parsing (SIGDN_DESKTOPABSOLUTEPARSING
) and editing (SIGDN_DESKTOPABSOLUTEEDITING
) display names:
Path | Editing | Parsing |
---|---|---|
C:\ | "C:" | "C:" |
C:\Windows | "C:\Windows" | "C:\Windows" |
Desktop | "Desktop" | "C:\Users\Ian\Desktop" |
Computer | "This PC" | "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" |
Recycle Bin | "Recycle Bin" | "::{645FF040-5081-101B-9F08-00AA002F954E}" |
Documents Library | "Libraries\Documents" | "::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\Documents.library-ms" " |
Startup | "C:\Users\Ian\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" | "C:\Users\Ian\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" |
How to parse them when the user types in them in?
I can use IFileOpenDialog
to let the user select one of these folders. But i'd really like the user to be able to type
- "C:\Users"
- "C:\Windows\Fonts"
- "This PC"
- "Recycle Bin"
- "Libraries"
- "Startup"
- "Fonts"
and be able to parse it into an IShellItem
.
The problem is that some of the paths are not parsed by SHCreateItemFromParsingName
:
SHCreateItemFromParsingName("C:\")
: ParsesSHCreateItemFromParsingName("C:\Windows")
: ParsesSHCreateItemFromParsingName("")
: Parses (but becomes "This PC")SHCreateItemFromParsingName("This PC")
: FailsSHCreateItemFromParsingName("Recycle Bin")
: FailsSHCreateItemFromParsingName("Libraries")
: FailsSHCreateItemFromParsingName("OneDrive")
: FailsSHCreateItemFromParsingName("Libraries\Documents")
: FailsSHCreateItemFromParsingName("Network")
: FailsSHCreateItemFromParsingName("Startup")
: Fails
Meanwhile, the IFileOpenDialog control that my program uses can parse them fine:
How can i parse the various special shell name places that a user might type in (that Windows Explorer and the IFileOpen dialog can parse) into an IShellItem
for that folder?
The real question is that i want the user to be able to have a recent MRU list that contains things like:
- C:\Windows
- Recycle Bin
- This PC
and be able to parse them later.