By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,082 Members | 2,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,082 IT Pros & Developers. It's quick & easy.

type of file from extension but no filename

P: n/a
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.
May 19 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.