tags:

views:

1101

answers:

3

Is there a way to get an associated icon in C# without using any DllImports?

When I use Icon.ExtractAssociatedIcon I don't seem to get the icon for drives, folders, SpecialFolder's in Environment or any files on network attached folders. So is there any other way to get an icon using .NET?

A: 

Not an answer to your question but might be of use.

You can get most of ms windows icons from this file

$VisualStudiosInstallationDirectory\Common7\VS2008ImageLibrary\VS2008ImageLibrary.zip

Substitute 2008 for 2005 if you still use VS2005

Nifle
A: 

This article with code on CodeProject might be of help.

Extract icons from EXE or DLL files

Nifle
If you download his source code he is using DllImport("kernel32"...). I want to be able to use my code on non Windows systems as well (without having to change a whole lot of code with #if-statements).
Patrick
I doubt there is a portable way to extract icons across os'es
Nifle
Java is portable, and as far as I know Java can extract all kind of icons, or am I wrong?
Patrick
+3  A: 

.Net have only one method for extracting associated icons, and you already mentioned about it. Every lib you can find uses pinvokes, because they get icons from windows. So if you need to fully portable icon extraction engine, you must write it by yourself, sadly, but this is the only way (and hide all system specific code inside).

arbiter
Hm, well that's unfortunate. Thanks for your help.
Patrick