C# How to set folder icon?

2019-05-23 15:39发布

问题:

I use FilePathDialog.SelectedPath get folder's path I also know icon's path but i don't know how to set that folder's icon

回答1:

this website has a very similar example



回答2:

You have to write the desktop.ini file.

[.ShellClassInfo]
IconResource=Icon.ico,0
IconFile=Icon.ico
IconIndex=0
[ViewState]
Mode=
Vid=
FolderType=Pictures

C# code

string dir = "Folder Path";   
string[] lines = { "[.ShellClassInfo]", "IconResource=Icon.ico,0", "[ViewState]", "Mode=", "Vid=", "FolderType=Pictures" };
File.WriteAllLines(dir + @"\desktop.ini", lines);

IconResource: {Icon Path},0
FolderTypes: Generic, Documents, Pictures, Music, Videos

If you need more information, check this GitHub project: https://github.com/FIC-Folder-Icon-Changer



标签: c# icons