private static IKnownFolder GetKnownFolder(IKnownFolderNative knownFolderNative)
{
Debug.Assert(knownFolderNative != null, "Native IKnownFolder should not be null.");
// Get the native IShellItem2 from the native IKnownFolder
IShellItem shellItem;
Guid guid = new Guid(InterfaceGuids.IShellItem);
HResult hr = knownFolderNative.GetShellItem(0, ref guid, out shellItem);
if (hr != HResult.S_OK) return null;
bool isFileSystem = false;
// If we have a valid IShellItem, try to get the FileSystem attribute.
if (shellItem != null)
{
SFGAO sfgao;
shellItem.GetAttributes(SFGAO.FILESYSTEM, out sfgao);
// Is this item a FileSystem item?
isFileSystem = (sfgao & SFGAO.FILESYSTEM) != 0;
}
// If it's FileSystem, create a FileSystemKnownFolder, else NonFileSystemKnownFolder
if (isFileSystem)
{
return FileSystemKnownFolder.Create(knownFolderNative);
}
var knownFsFolder = new NonFileSystemKnownFolder(knownFolderNative);
return knownFsFolder;
}