diff --git a/PInvoke/Shell32/KnownFolderIdExt.cs b/PInvoke/Shell32/KnownFolderIdExt.cs
index 15fba3dd..89fe2bbe 100644
--- a/PInvoke/Shell32/KnownFolderIdExt.cs
+++ b/PInvoke/Shell32/KnownFolderIdExt.cs
@@ -35,10 +35,15 @@ namespace Vanara.PInvoke
/// Retrieves the Guid associated with a .
/// The known folder.
/// The GUID.
- public static Guid Guid(this KNOWNFOLDERID id)
+ public static Guid Guid(this KNOWNFOLDERID id) => AssociateAttribute.GetGuidFromEnum(id);
+
+ /// Retrieves the IShellItem associated with a .
+ /// The known folder.
+ /// The instance.
+ public static IShellItem GetIShellItem(this KNOWNFOLDERID id)
{
- var attr = typeof(KNOWNFOLDERID).GetField(id.ToString()).GetCustomAttributes(typeof(KnownFolderDetailAttribute), false);
- return attr.Length > 0 ? ((KnownFolderDetailAttribute) attr[0]).guid : System.Guid.Empty;
+ SHGetKnownFolderItem(id.Guid(), KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, SafeTokenHandle.Null, typeof(IShellItem).GUID, out var ppv).ThrowIfFailed();
+ return (IShellItem) ppv;
}
/// Retrieves the associated with the .
diff --git a/PInvoke/Shell32/ShObjIdl.IKnownFolder.cs b/PInvoke/Shell32/ShObjIdl.IKnownFolder.cs
index 1db3c8b3..85612f5f 100644
--- a/PInvoke/Shell32/ShObjIdl.IKnownFolder.cs
+++ b/PInvoke/Shell32/ShObjIdl.IKnownFolder.cs
@@ -992,17 +992,16 @@ namespace Vanara.PInvoke
/// Provides information about a .
[AttributeUsage(AttributeTargets.Field)]
- internal class KnownFolderDetailAttribute : Attribute
+ internal class KnownFolderDetailAttribute : AssociateAttribute
{
- public Environment.SpecialFolder Equivalent = (Environment.SpecialFolder) 0XFFFF;
- internal Guid guid;
-
- /// Initializes a new instance of the class with a GUID for the .
+ /// Initializes a new instance of the class with a GUID for the .
/// The GUID for the .
- public KnownFolderDetailAttribute(string knownFolderGuid)
+ public KnownFolderDetailAttribute(string knownFolderGuid) : base(knownFolderGuid)
{
- guid = new Guid(knownFolderGuid);
}
+
+ /// The equivalent SpecialFolder.
+ public Environment.SpecialFolder Equivalent = (Environment.SpecialFolder) 0XFFFF;
}
}
}
\ No newline at end of file