Search code examples
c#.netwindowsiconsfile-type

How do I get common file type icons in C#?


As seen in This SO question on getting icons for common file types, it's quite possible for a windows program to get the icons for a registered file type using the C++ Shell API. These icons may or may not exist on disk - for example, we wanted to make our own custom file browser and want to display the system-associated icon with the file.

Is there a native C# way to get the icons for various file types (and if so, how) or must it be done through PInvoke with shell API?

And as a follow up, if there is a native .NET way of doing it, is there a cross-platform way of doing it?


Solution

  • Take a look at: http://mvolo.com/display-pretty-file-icons-in-your-aspnet-applications-with-iconhandler/

    It's not the cleanest solution but it works. Otherwise, try to get your hands on a library of Icons that's based on mime type or file extension.