Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Icon Class
Icon Methods
 ExtractAssociatedIcon Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
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)
Visual Basic (Declaration)
Public Shared Function ExtractAssociatedIcon ( _
    filePath As String _
) As Icon
Visual Basic (Usage)
Dim filePath As String
Dim returnValue As Icon

returnValue = Icon.ExtractAssociatedIcon(filePath)
C#
public static Icon ExtractAssociatedIcon(
    string filePath
)
Visual C++
public:
static Icon^ ExtractAssociatedIcon(
    String^ filePath
)
JScript
public static function 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 contained in the specified file.
ExceptionCondition
ArgumentException

filePath does not indicate a valid file.

-or-

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.

Visual Basic
Private Sub ExtractAssociatedIconEx()
    Dim ico As Icon = Icon.ExtractAssociatedIcon("C:\WINDOWS\system32\notepad.exe")
    Me.Icon = ico

End Sub

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

}

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker