[Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-04-21
Medium Priority
Last Modified: 2010-04-23
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"))
TreeViewItem1.ImageIndex = ImageList1.Items.Count - 1
Question by:maidinhtai
  • 2
  • 2
LVL 96

Accepted Solution

Bob Learned earned 2000 total points
ID: 16510516

Author Comment

ID: 16510894
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!
LVL 96

Expert Comment

by:Bob Learned
ID: 16510926
Imports System.Reflection
Imports System.Runtime.InteropServices

Public Class App

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

End Class


Author Comment

ID: 16511124
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.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question