Skip to main content
.NET Framework Class Library
Icon..::.ExtractAssociatedIcon Method

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

Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Syntax
Public Shared Function ExtractAssociatedIcon ( _
	filePath As String _
) As Icon
public static Icon ExtractAssociatedIcon(
	string filePath
)
public:
static Icon^ ExtractAssociatedIcon(
	String^ filePath
)
static member ExtractAssociatedIcon : 
        filePath:string -> Icon 

Parameters

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.
Exceptions
ExceptionCondition
ArgumentException

The filePath does not indicate a valid file.

-or-

The filePath indicates a Universal Naming Convention (UNC) path.

Remarks

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.

Examples

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 Sub ExtractAssociatedIconEx()
    Dim ico As Icon = Icon.ExtractAssociatedIcon("C:\WINDOWS\system32\notepad.exe")
    Me.Icon = ico

End Sub


private void ExtractAssociatedIconEx()
{
    Icon ico =
        Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
    this.Icon = ico;

}

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.