Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing WPF application.in my application need to get the system icon only by the file extension not by the path.

What I have tried:

what i am getting is while using shellInfo,
i need to give the full path eg:- c:\temp\capture.mp4 then getting the default icon of mp4.
what i need is have to give only (.mp4) or(.rar) extension.
Posted
Updated 5-Jan-21 21:47pm
Comments
Richard MacCutchan 6-Jan-21 3:47am    
If I remember correctly this information is kept in the registry. Google should be able to find you the details.

1 solution

As far as I know, you have to have a file path to get the icon - but it doesn't have to be a valid file of that type.
So use a temporary file and get the icon from that:
C#
string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".mp4");
FileStream file = File.Create(path);
file.Close();
Icon im = Icon.ExtractAssociatedIcon(path);
File.Delete(path);
 
Share this answer
 
Comments
Fazil13 6-Jan-21 5:40am    
Thanks a lot!
OriginalGriff 6-Jan-21 5:44am    
You're welcome!
Fazil13 6-Jan-21 5:49am    
For folder how to get?
OriginalGriff 6-Jan-21 6:16am    
That gets complicated: you need to start playing with this, which will require a DLLImport:
https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shgetstockiconinfo

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900