On Windows we would like to access the icon associated with a file type, i.e .mp3
. However, from what I can tell there is only this method: ExtractAssociatedIcon
[1] which requires the file to exists.
So can I get access to the icons somehow ?
Asked
Active
Viewed 103 times
0

Lars Nielsen
- 2,005
- 2
- 25
- 48
-
Yes, but I warn you it won't be easy. As you can see in [this question](https://stackoverflow.com/questions/524137/get-icons-for-common-file-types) you can call a [shell function](https://learn.microsoft.com/en-gb/windows/desktop/api/shellapi/nf-shellapi-shgetfileinfoa) to get the icon associated with a file extension without requiring an actual file. However you need to use PInvoke to call this from managed code - [this question](https://stackoverflow.com/questions/1599235/how-do-i-fetch-the-folder-icon-on-windows-7-using-shell32-shgetfileinfo) shows a partial example. – stuartd Oct 10 '18 at 10:20
-
… a bit of [searching](https://duckduckgo.com/?q=C%23+SHGetFileInfo+icon&t=ffab&ia=qa) might find you something you can use. – stuartd Oct 10 '18 at 10:21
-
@stuartd and I found a lot of answers where it said it didn't work – Lars Nielsen Oct 10 '18 at 10:28
-
If it didn't work, then it wasn't being called correctly. – stuartd Oct 10 '18 at 10:32
-
_"ExtractAssociatedIcon requires the file to exists"_ - yes it does, but **it does not have to be valid for the file type** - you can create a temporary text file called "textfile.mp3" and `ExtractAssociatedIcon` will return you the correct icon. – stuartd Oct 10 '18 at 10:54