I know that this must be incredibly easy - It's unbelievable how long I have searched for an answer to this question based on how simple it is in VB6. I simply want to extract an Icon from an EXE File using Icon.ExtractAssociatedIcon, and then save this icon file to my hard drive.
So, here is what I have, and I will also show you what I have tried so you don't think I'm being lazy.
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
string s = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\IconData.ico";
Icon ico = Icon.ExtractAssociatedIcon(ofd.FileName);
Bitmap bmp = ico.ToBitmap();
bmp.Save(s, System.Drawing.Imaging.ImageFormat.Icon);
The above code just makes a file called "IconData.ico" on my desktop which is 0 bytes in length. Again, I am sure this must be incredibly easy to do, but for the life of my I can't figure it out.
Thank you!