public static Bitmap GetIcon(string ext) { // Icon.ExtractAssociatedIcon only works with embedded like an exe's icon Bitmap img = null; try { SHFILEINFO info = new SHFILEINFO(); SHGetFileInfo( ext, 0, ref info, (uint)Marshal.SizeOf(info), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON); img = Icon.FromHandle(info.hIcon).ToBitmap(); DestroyIcon(info.hIcon); } catch { } return img; }
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);