问题
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
来源:https://stackoverflow.com/questions/6531898/c-sharp-how-to-set-folder-icon