type of file from extension but no filename

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hello,

I want to get a list of file types from a big list of extensions.

I know there exists an api call (see below), but it only works when you have
a file name.
SHGetFileInfo(FileName, 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_TYPENAME)
Return shinfo.szTypeName

But this only works when passing an actuual filename (fe:
"C:\WINDOWS\WIN.INI")


When getting the icon from only the extension seems to work:
hImgLarge = SHGetFileInfo(ext, 0, shinfo, Marshal.SizeOf(shinfo),
SHGFI_USEFILEATTRIBUTES Or SHGFI_ICON Or SHGFI_LARGEICON)
Return System.Drawing.Icon.FromHandle(shinfo.hIcon)

Here I can pass the extension only (fe: ".exe")


Is this possible?
Grtz.
 
I want to get a list of file types from a big list of extensions.
I know there exists an api call (see below), but it only works when you have
a file name.
SHGetFileInfo(FileName, 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_TYPENAME)
Return shinfo.szTypeName

But this only works when passing an actuual filename (fe:
"C:\WINDOWS\WIN.INI")


When getting the icon from only the extension seems to work:
hImgLarge = SHGetFileInfo(ext, 0, shinfo, Marshal.SizeOf(shinfo),
SHGFI_USEFILEATTRIBUTES Or SHGFI_ICON Or SHGFI_LARGEICON)
Return System.Drawing.Icon.FromHandle(shinfo.hIcon)

Here I can pass the extension only (fe: ".exe")


The key is to specify SHGFI_USEFILEATTRIBUTES like you did for the
icon. Should work for the file type as well.


Mattias
 
Back
Top