This documentation is archived and is not being maintained.

Icon.ExtractAssociatedIcon Method

Returns an icon representation of an image contained in the specified file.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public static Icon ExtractAssociatedIcon (
	string filePath
public static Icon ExtractAssociatedIcon (
	String filePath
public static function ExtractAssociatedIcon (
	filePath : String
) : Icon
Not applicable.



The path to the file that contains an image.

Return Value

The Icon representation of the image contained in the specified file.

Exception typeCondition


filePath does not indicate a valid file.


filePath indicates a Universal Naming Convention (UNC) path.

A relative path is assumed to be relative to the current working directory.

When ExtractAssociatedIcon is used with bitmaps, a thumbnail image may be returned instead of an icon if the system running the application has a registry setting that causes bitmap files to be shown as thumbnail images.

The following code example demonstrates how to use the ExtractAssociatedIcon method. To run this example, paste the code into a Windows Form and call ExtractAssociatedIconEx from the form's constructor or Load event handler.

private void ExtractAssociatedIconEx()
    Icon ico =
    this.Icon = ico;


Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0