473,785 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ExtractAss ociatedIcon, 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 4079
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.co m

"Matt" <Ma********@cov enanteyes.comwr ote 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.ExtractAss ociatedIcon, 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.lo g" works
fine.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:e4******** ******@TK2MSFTN GP02.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.co m

"Matt" <Ma********@cov enanteyes.comwr ote 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.ExtractAs sociatedIcon, 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
2879
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 displayed at the left of the name of the page. How do I do this? I am using Frontpage 2002, but know how to edit HTML manually. Thanks,
2
11995
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 found that I can use the "Path.GetExtension()" to retrieve the extension of the file. But, how to get the icon from the extension that display in windows explorer and show that in List View? Thanks in advance!!!
5
3173
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 database. Therefore the file doesnt really exist on the user's hard drive. All the file extracting techniques require that I have the actual file on the drive in order to get an icon for it. There is a workaround for this: i could create dummy files with...
13
2082
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 part of the .resx file. Its like VB6 when I could use load all my images from a resource file. Lou
1
1209
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
8216
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, 'avi'. Think of a P2P program. The user searched for 'avi', and the program should show result avi files with associated icons but there's no actual file on the users system. Maybe a workaround is to create a dumb (0KB) temp.avi file somewhere on...
1
1649
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 file extension not on the attributes of the file. i have gone trough the registry but things are not very clear. Windows has listed all the file extensions avaliable there, but there is no general way to extract icons for those extension... kindly...
2
1345
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 - http://www.windwardreports.com/film.htm
5
5710
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 to open through the app 2. user drags file onto the app's icon (desktop) or from "Send To" popup 3. app opens upon "drop" 4. app recognized the file that was dropped on it and opens the file from
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.