views:

892

answers:

3

I have a form that displays file information in a TabControl, and I'd like the pages to have the file's icon in their tab. How do I get the icon associated with a file type?

I'd prefer solutions that don't involve looking things up in the registry, but if that's the only way then so be it.

+4  A: 

CodeProject has some classes you can download.

First get the FileAssociationInfo, and from that get the ProgramAssociationInfo. The PAI object can give you the icon.

FileAssociationInfo fai = new FileAssociationInfo(".bob");
ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
ProgramIcon icon = pai.DefaultIcon;
Bill the Lizard
Looks good, but how do I get the FileAssociationInfo? There's nothing on MSDN about any of those classes.
Simon
Here you can download the classes: http://channel9.msdn.com/playground/Sandbox/249856-System-File-Association/
Ikke
My bad, I forgot to include the link.
Bill the Lizard
A: 

You might look here for an example.

Marc Gravell
+1  A: 

System.Drawing.Icon.ExtractAssociatedIcon(string filePath)

leppie
That only works for actual files, not file *type*s.
Simon