Home All Groups Group Topic Archive Search About

type of file from extension but no filename

Author
19 May 2006 5:41 AM
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.

Author
19 May 2006 5:08 PM
Mattias Sjögren
Show quote Hide quote
>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.