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?
 
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!
0
 
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
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.