I had a function a while back that would enumerate images within a DLL and another that would extract one. It was never really all that useful but it did give me a couple hours of fun searching through various DLLs. This was back in the days when everyone was trying to learn C++ (and yes, was written in C++). So why does this little story matter? Well I was bored today and wondered how easy it would be to do a similar thing in C#. Which led me to something even more useful. Extracting the icon associated with a file type:
1: /// <summary>
2: /// Extracts an icon associated with a file
3: /// </summary>
4: /// <param name="FileName">File to extract the icon from</param>
5: /// <returns>Returns the extracted icon</returns>
6: public static Bitmap ExtractIcon(string FileName)
7: {
8: return System.Drawing.Icon.ExtractAssociatedIcon(FileName).ToBitmap();
9: }
That's it. One line of code and you can get the icon associated with a file. I remember doing something similar took me a couple hundred lines... And I had to walk up hill to the punch card reader... Both ways... Kids today have it easy. Although no idea why I used punch cards considering I'm in my 20s... Anyway, I hope you can find some use for that bit of code. So try it out, leave feedback, and happy coding.