Example #1
0
 public static string GetFileDescription(string path)
 {
     NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO();
        NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi),
     NativeMethods.SHGetFileInfoFlags.SHGFI_DISPLAYNAME);
        return shfi.szDisplayName;
 }
Example #2
0
 public static Icon GetFileIcon(string path)
 {
     NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO();
        NativeMethods.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi),
     NativeMethods.SHGetFileInfoFlags.SHGFI_SMALLICON |
     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()));
 }