How to: get File icon of some file in windows Explorer

For example, how can I get the icon of the notepad file, such as somefile.txt. I want to get the icon image and assign it to a ListViewItem. I am writing a windows explorer emulator.
Something likes this:

Dim x as Bitmap = new Bitmap(GetIconImage("C:\somefile.txt"))
ImageList1.Items.Add(x)
TreeViewItem1.ImageIndex = ImageList1.Items.Count - 1
LVL 3
maidinhtaiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maidinhtaiAuthor Commented:
When I try running the sample in the link, I receive this error:
----------------------------------------------------------------------------------------------
Private Sub frmIconViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Const OFFSET As Integer = 20

        Dim extractor As New IconExtractor
        Dim listIcons() As Icon = extractor.ExtractIcons("c:\windows\system32\progman.exe", App.AppInstance) 'This is the line I receive the error:Error      3      Name 'App' is not declared.
----------------------------------------------------------------------------------------------
I don't know what App means? Could you explain!
Bob LearnedCommented:
Imports System.Reflection
Imports System.Runtime.InteropServices

Public Class App

  Public Shared ReadOnly Property AppInstance() As IntPtr
    Get
       Return Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly().GetModules()(0))
    End Get
  End Property  'AppInstance

End Class

Bob
maidinhtaiAuthor Commented:
It's so great. My problem is almost solved. There's just a small thing more: how can I get the application path of the appliction that used to open the file. For example, I have a file "C:\sample.txt". The application path of the file opening that file is "%SystemRoot%\system32\notepad.exe". What I want now is getting that application path when I have the string "C:\sample.txt".
Thanks a lot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.