7

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.

Simon
  • 25,468
  • 44
  • 152
  • 266

2 Answers2

12

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;
Irshad
  • 3,071
  • 5
  • 30
  • 51
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
10

System.Drawing.Icon.ExtractAssociatedIcon(string filePath)

leppie
  • 115,091
  • 17
  • 196
  • 297