Change Folder Icon Programmatically

  • Thread starter Thread starter Phil Hey
  • Start date Start date
P

Phil Hey

Hi,


I can change the icon for a folder by right clicking on it > going to the
customize tab > and selecting Choose Picture.


Does anyone know if it is possible to do this programmatically from a
windows forms application?


Thanks


Phil
 
Phil said:
Hi,


I can change the icon for a folder by right clicking on it > going to the
customize tab > and selecting Choose Picture.


Does anyone know if it is possible to do this programmatically from a
windows forms application?


Thanks


Phil

Maybe if you change the registry entry at:
hkey_classes_root\folder\DefaultIcon

That where I think the icon definition is stored.
 
Maybe if you change the registry entry at:
hkey_classes_root\folder\DefaultIcon

That where I think the icon definition is stored.
--


Yes, but I dont want to change all the folders just certain ones, thanks
anyway

Phil
 
Phil said:
Yes, but I dont want to change all the folders just certain ones, thanks
anyway

Phil
I don't think you can since Windows displays the icons according to
filetype. A folder is just a folder to Windows. So it will look up the
icon there and display it. Just like you can't display icon A for one
textfile(.txt) and icon B for another textfile(.txt). So unless you make
a shortcut and change the icon of that I can't see a way.

I might be wrong though, in that case I would love to see how it's done :)
 
Phil said:
I can change the icon for a folder by right clicking on it > going to the
customize tab > and selecting Choose Picture.

I think if you have an image inside the folder called folder.jpg Windows
will automatically use this for the folder image. You could copy this in
in your code. Not sure if this helps at all.
 
Rinze said:
I don't think you can since Windows displays the icons according to
filetype.

You can definatelly do this (manually at least) for individual folders
rather than all folders as i am looking at an example of this now. Maybe if
I explain the situation it will help:

I have a drive on the server called Jobs (j:) in this drive I have folders
for each of the jobs lablled 'J1194' for example. When, in my application, a
job is made in-active i want this folder to appear with a red cross through
it to in dicate that it is closed.
I think if you have an image inside the folder called folder.jpg Windows
will automatically use this for the folder image. You could copy this in
in your code. Not sure if this helps at all.

Ok, I have tried this and it works but only if you are viewing the folders
in Thumbnail view not in any of the other views.

Anyway thanks for the help

Phil
 
Hi Phil

For the Thumbnails view, you should get a picture showing automatically. If
you set an icon for other views, then you get a Desktop.ini file created in
the folder, with this as the content:

[.ShellClassInfo]
IconFile=%SystemRoot%\system32\SHELL32.dll
IconIndex=21

This code creates the file and works...cool!

Dim fs As New IO.FileStream("C:\Test\Desktop.ini", IO.FileMode.Create)
Dim tw As New IO.StreamWriter(fs)
tw.WriteLine("[.ShellClassInfo]")
tw.WriteLine("IconFile=%SystemRoot%\system32\SHELL32.dll")
tw.WriteLine("IconIndex = 21")
tw.Close()
fs.Close()

HTH

Nigel
 
Phil said:
You can definatelly do this (manually at least) for individual folders
rather than all folders as i am looking at an example of this now. Maybe if
I explain the situation it will help:

I have a drive on the server called Jobs (j:) in this drive I have folders
for each of the jobs lablled 'J1194' for example. When, in my application, a
job is made in-active i want this folder to appear with a red cross through
it to in dicate that it is closed.

That may be something XP specific I think. On this Win98 computer I
can't change the icon for a specific folder. But elzico might be on to
something.
 
Nigel you are an absolute legend, thanks. :-)

One thing of note is that the folder must be a system folder (whatever that
means). Here is a link to a knowledge base article with some info :

http://msdn.microsoft.com/library/d...hell_basics/shell_basics_extending/custom.asp

Phil

Nigel Armstrong said:
Hi Phil

For the Thumbnails view, you should get a picture showing automatically.
If
you set an icon for other views, then you get a Desktop.ini file created
in
the folder, with this as the content:

[.ShellClassInfo]
IconFile=%SystemRoot%\system32\SHELL32.dll
IconIndex=21

This code creates the file and works...cool!

Dim fs As New IO.FileStream("C:\Test\Desktop.ini",
IO.FileMode.Create)
Dim tw As New IO.StreamWriter(fs)
tw.WriteLine("[.ShellClassInfo]")
tw.WriteLine("IconFile=%SystemRoot%\system32\SHELL32.dll")
tw.WriteLine("IconIndex = 21")
tw.Close()
fs.Close()

HTH

Nigel
Phil Hey said:
Hi,


I can change the icon for a folder by right clicking on it > going to the
customize tab > and selecting Choose Picture.


Does anyone know if it is possible to do this programmatically from a
windows forms application?


Thanks


Phil
 
Back
Top