public static string GetFileDescription(string path) { ShellApi.NativeMethods.SHFILEINFO shfi = new ShellApi.NativeMethods.SHFILEINFO(); ShellApi.NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), ShellApi.NativeMethods.SHGetFileInfoFlags.SHGFI_DISPLAYNAME); return shfi.szDisplayName; }
public static Icon GetFileIcon(string path) { ShellApi.NativeMethods.SHFILEINFO shfi = new ShellApi.NativeMethods.SHFILEINFO(); ShellApi.NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), ShellApi.NativeMethods.SHGetFileInfoFlags.SHGFI_SMALLICON | ShellApi.NativeMethods.SHGetFileInfoFlags.SHGFI_ICON); if (shfi.hIcon != IntPtr.Zero) return Icon.FromHandle(shfi.hIcon); else throw new IOException(string.Format(CultureInfo.CurrentCulture, "Could not load file icon from {0}", path), Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error())); }