It can be done with SHCreateDefaultContextMenu
(or by converting Displaying a property sheet for multiple files in C#)
(Edit : SHMultiFileProperties might be simpler...)
How to Open Properties dialog for multiple selected files using WIN FORM C#

I hope you all are doing well.
Using: WIN-FORM, C#
I am using the code from this link to open the file properties of a single file from my app and, this works great.
What I have been looking for and seems that nothing is found, is how to get the properties for 2 or more selected files?
In the image below, I used File Explorer and I selected several files and got the files properties by right click > Properties.
How could I implement this in c# code or could the code in the provided link be modified?
Regards,
2 answers
Sort by: Most helpful
-
Castorix31 71,606 Reputation points
2022-11-02T15:17:34.867+00:00 -
Castorix31 71,606 Reputation points
2022-11-02T21:27:35.093+00:00 A test with SHMultiFileProperties, with 2 .jpg files :
IntPtr pidlParent = IntPtr.Zero, pidlFull = IntPtr.Zero, pidlItem = IntPtr.Zero; uint rgflnOut = 0; var aPidl = new IntPtr[255]; uint nIndex = 0; HRESULT hr = SHILCreateFromPath("E:\\test.jpg", out pidlFull, ref rgflnOut); if (hr == HRESULT.S_OK) { pidlItem = ILFindLastID(pidlFull); aPidl[nIndex++] = ILClone(pidlItem); ILRemoveLastID(pidlFull); //pidlParent = ILClone(pidlFull); ILFree(pidlFull); } hr = SHILCreateFromPath("E:\\test2.jpg", out pidlFull, ref rgflnOut); if (hr == HRESULT.S_OK) { pidlItem = ILFindLastID(pidlFull); aPidl[nIndex++] = ILClone(pidlItem); ILRemoveLastID(pidlFull); pidlParent = ILClone(pidlFull); ILFree(pidlFull); } System.Runtime.InteropServices.ComTypes.IDataObject pDO = null; hr = CIDLData_CreateFromIDArray(pidlParent, nIndex, aPidl, out pDO); if (hr == HRESULT.S_OK) { hr = SHMultiFileProperties(pDO, 0); } if (pidlParent != IntPtr.Zero) ILFree(pidlParent); for (int i = 0;i < nIndex; i++) { if (aPidl[i] != IntPtr.Zero) ILFree(aPidl[i]); }
Declarations :
public enum HRESULT : int { S_OK = 0, S_FALSE = 1, E_NOINTERFACE = unchecked((int)0x80004002), E_NOTIMPL = unchecked((int)0x80004001), E_FAIL = unchecked((int)0x80004005), } [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern HRESULT SHILCreateFromPath([MarshalAs(UnmanagedType.LPWStr)] string pszPath, out IntPtr ppIdl, ref uint rgflnOut); [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern IntPtr ILFindLastID(IntPtr pidl); [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern IntPtr ILClone(IntPtr pidl); [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern Boolean ILRemoveLastID(IntPtr pidl); [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern void ILFree(IntPtr pidl); [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern HRESULT CIDLData_CreateFromIDArray(IntPtr pidlFolder, uint cidl, IntPtr[] apidl, out System.Runtime.InteropServices.ComTypes.IDataObject ppdtobj); [DllImport("Shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern HRESULT SHMultiFileProperties(System.Runtime.InteropServices.ComTypes.IDataObject pdtobj, uint dwFlags);