/// <summary> /// Gets a <see cref="PropertyDescriptionList"/> from the specified <see cref="PropertyKey"/> /// </summary> /// <param name="key">The property list being requested</param> /// <returns>The list of property descriptions specified by the property key</returns> public PropertyDescriptionList GetPropertyDescriptionList(PropertyKey key) { IntPtr pUnk; _pItem.GetPropertyDescriptionList(key.MarshalledPointer, IID.IProperyDescriptionList, out pUnk); PropertyDescriptionList list = new PropertyDescriptionList(pUnk); Marshal.Release(pUnk); return(list); }
/// <summary> /// Creates a <see cref="PropertyDescriptionList"/> based on properties defined for a particular file or file type. /// </summary> /// <param name="path">The path or extension of the file type you want the PropertyDescriptionList for</param> /// <param name="propListKey">This <see cref="PropertyKey"/> defines the usage of the properties defined in the PropertyDescriptionList. It will be one of the /// <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ff521713(v=vs.85).aspx">PropList</a> values</param> public PropertyDescriptionList(string path, PropertyKey propListKey) { IShellItem2 item = null; FakeFile file = null; if (File.Exists(path)) { IntPtr itemUnk; IntPtr pidl = ILCreateFromPath(Path.GetFullPath(path)); SHCreateItemFromIDList(pidl, IID.IShellItem2, out itemUnk); item = (IShellItem2)Marshal.GetUniqueObjectForIUnknown(itemUnk); Marshal.Release(itemUnk); Marshal.FreeCoTaskMem(pidl); } else { string name; path = path.Substring(path.LastIndexOf('\\') + 1); if (path[0] == '.' || !(path.Contains('.'))) { name = Path.ChangeExtension("_fakeFile", path); } else { name = Path.GetFileName(path); } WIN32_FIND_DATA fd = new WIN32_FIND_DATA() { dwFileAttributes = FileAttributes.Normal, nFileSizeLow = 42 }; file = new FakeFile(ref fd, name); item = (IShellItem2)file.GetShellItem(); } try { IntPtr ppUnk = IntPtr.Zero;; item.GetPropertyDescriptionList(propListKey.MarshalledPointer, IID.IProperyDescriptionList, out ppUnk); _propList = (IPropertyDescriptionList)Marshal.GetUniqueObjectForIUnknown(ppUnk); Marshal.Release(ppUnk); } finally { if (item != null) { Marshal.FinalReleaseComObject(item); } if (file != null) { file.Dispose(); } } }
public static T GetPropertyDescriptionList <T>(this IShellItem2 psi, PROPERTYKEY keyType) where T : class { return((T)psi.GetPropertyDescriptionList(ref keyType, typeof(T).GUID)); }