Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-extract-the-icon-associated-with-a-file-in-windows-forms.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

1.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Extract the Icon Associated with a File 03/30/2017
csharp
vb
displaying a file name and its file type icon in a ListView control [Windows Forms]
file name extension icons [Windows Forms], displaying in a ListView
extracting icons associated with a file type [Windows Forms]
88e2ad8b-c34f-415a-84f2-dad756b5c928

How to: Extract the Icon Associated with a File in Windows Forms

Many files have embedded icons that provide a visual representation of the associated file type. For example, Microsoft Word documents contain an icon that identifies them as Word documents. When displaying files in a list control or table control, you may want to display the icon representing the file type next to each file name. You can do this easily by using the xref:System.Drawing.Icon.ExtractAssociatedIcon%2A method.

Example

The following code example demonstrates how to extract the icon associated with a file and display the file name and its associated icon in a xref:System.Windows.Forms.ListView control.

[!code-csharpSystem.Drawing.Icon.ExtractAssociatedIconEx#1] [!code-vbSystem.Drawing.Icon.ExtractAssociatedIconEx#1]

Compiling the Code

To compile the example:

  • Paste the preceding code into a Windows Form, and call the ExtractAssociatedIconExample method from the form's constructor or xref:System.Windows.Forms.Form.Load event-handling method.

    You will need to make sure that your form imports the xref:System.IO namespace.

See also