type of file from extension but no filename

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.
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top