Icon.ExtractAssociatedIcon Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

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

public static Icon ExtractAssociatedIcon(
	string filePath


Type: System.String

The path to the file that contains an image.

Return Value

Type: System.Drawing.Icon

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

Exception Condition

The filePath does not indicate a valid file.


The 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 that is 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;


.NET Framework
Available since 2.0
Return to top