How to get the system icon for any file/folder

后端 未结 2 614
迷失自我
迷失自我 2021-01-07 06:03

How can I retrieve the system icon associated with a file/folder so that I can show it in the list view adjacent to the file/folder name?

相关标签:
2条回答
  • 2021-01-07 06:23

    See Obtaining (and managing) file and folder icons using SHGetFileInfo in C#.

    0 讨论(0)
  • 2021-01-07 06:45

    You need to use Icon.ExtractAssociatedIcon

     Icon icon = Icon.ExtractAssociatedIcon(filepath);
    

    Take a look at Icon.ExtractAssociatedIcon documentation

    Note: this works only for files. For folders you need P/Invoke sample is here Edit: Page is now defunct, please refer to this copy on the Wayback Machine.

    0 讨论(0)
提交回复
热议问题