Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you know the file name of the file whose icon you want, you can use the <a href="http://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon.aspx" rel="nofollow" title="MSDN: Icon.ExtractAssociatedIcon Method"><code>ExtractAssociatedIcon</code></a> function for that purpose. e.g.</p> <pre><code>Icon ico = Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe"); </code></pre> <p>There is a catch to this method though. According to its documentation,</p> <blockquote> <p>When ExtractAssociatedIcon is used with bitmaps, a thumbnail image may be returned instead of an icon if the system that is running the application has a registry setting that causes bitmap files to be shown as thumbnail images.</p> </blockquote> <p>One other thing I found was that this method only extracts 32x32pixel icons.</p> <p>See <a href="http://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon.aspx" rel="nofollow" title="MSDN: Icon.ExtractAssociatedIcon Method">System.Drawing.Icon.ExtractAssociatedIcon (MSDN)</a> for more how to use this method.</p> <hr> <p>For a more robust icon extractor, I'd suggest you look at the <a href="http://www.codeproject.com/KB/system/OSIcon.aspx" rel="nofollow" title="OSIcon - CodeProject">OSIcon</a> project on CodeProject.<br> It allows you to get the associated icon of any file using its file name <em>or</em> extension.<br> Here is a sample code for doing that:</p> <pre><code>OSIcon.WinAPI.Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO(); Icon icon = OSIcon.IconReader.GetFileIcon(".png", IconReader.IconSize.Large, false, ref shfi); </code></pre> <p>This is the link to the project: <a href="http://www.codeproject.com/KB/system/OSIcon.aspx" rel="nofollow" title="OSIcon - CodeProject">http://www.codeproject.com/KB/system/OSIcon.aspx</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload