473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Icon from fle extension

How do I get a Icon for display in a list view from just the file extension?

If I have a file that exists on a local machine I can use
Icon.ExtractAssociatedIcon, but in this case the files are not on the
machine. The extension may give the incorrect informaton about file type,
but it is all the information I have.

There seems to be some information in the registry about this, but will I
always have permission to view this information in the registery?
Jul 20 '07 #1
2 4058
Matt,

Due to things like shell extensions, the icon that can be returned might
not be what you expect based on the registry information. This is an
implementation detail, and should be avoided.

Rather, what you want to do is call the SHGetFileInfo function in the
windows API through the P/Invoke layer (you can get the definition from
http://www.pinvoke.net). You can pass it a wildcard for the filename (with
extension) and it will return you the icon for that file (you might possibly
get a more specific icon by passing the complete path of the file).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Matt" <Ma********@covenanteyes.comwrote in message
news:iI******************************@t-one.net...
How do I get a Icon for display in a list view from just the file
extension?

If I have a file that exists on a local machine I can use
Icon.ExtractAssociatedIcon, but in this case the files are not on the
machine. The extension may give the incorrect informaton about file type,
but it is all the information I have.

There seems to be some information in the registry about this, but will I
always have permission to view this information in the registery?

Jul 20 '07 #2
I have tried to do this. It works fine for files that exist that I have
found, but I cannot get the wildcards to work. What do the wildcards for
this api look like?
".gif" does not work. ". "*.gif" does not work. But, "C:\logs.log" works
fine.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:e4**************@TK2MSFTNGP02.phx.gbl...
Matt,

Due to things like shell extensions, the icon that can be returned
might not be what you expect based on the registry information. This is
an implementation detail, and should be avoided.

Rather, what you want to do is call the SHGetFileInfo function in the
windows API through the P/Invoke layer (you can get the definition from
http://www.pinvoke.net). You can pass it a wildcard for the filename
(with extension) and it will return you the icon for that file (you might
possibly get a more specific icon by passing the complete path of the
file).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Matt" <Ma********@covenanteyes.comwrote in message
news:iI******************************@t-one.net...
>How do I get a Icon for display in a list view from just the file
extension?

If I have a file that exists on a local machine I can use
Icon.ExtractAssociatedIcon, but in this case the files are not on the
machine. The extension may give the incorrect informaton about file
type, but it is all the information I have.

There seems to be some information in the registry about this, but will I
always have permission to view this information in the registery?


Jul 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ed Isenberg | last post by:
I notice that a lot of Web pages have an icon that is displayed preceding the URL in the place in the browser where the URL is displayed. When I bookmark or add this to Favorites the icon is also...
2
by: weixiang | last post by:
Hi, I am writing a program that have some filenames collected in a List View. Then I need to display the correct icon for each of them according to the extension of the file. In the document I...
5
by: IcingDeath via DotNetMonster.com | last post by:
I am building this SQL Server database app in which i can store files. In order to display files I want to have the app show the associated icon for the extension of the file that is in the...
13
by: Lou | last post by:
if I add a new item (Solution Items) to my project and its an icon(.ico), how can I reference that file when I am coding, Do I have to also add it to an image control, I don't want the file to be...
1
by: Neo | last post by:
please tell me, how get icon structure associated with extension? if my file extention is (Doc) then how and where i get icon of document file? regards, Mohammad Omer Nasir
4
by: Sin Jeong-hun | last post by:
I already found that I have to use SHGetFileInfo to get the System's associated icon with that file. But what about I just want to get associated icon for some specific extensions? For example,...
1
by: Nicky | last post by:
when we change the extension of a file in windows, its icon also changes..... how does windows do tht. in my application i require a similar approach. i want the icon to be dependent on the...
2
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; How can I set the icon for the DLL file a portla deploy project creates? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com Cubicle Wars -...
5
by: =?Utf-8?B?Um9i?= | last post by:
Hi all, I want to fire the drag events when someone drags a file over the application's icon. This means the application has not opened yet. Scenario would be: 1. user selects file they want...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.