How do I get the default icon for any file type in Windows?
3 answers
try it
public static Hashtable GetTypeAndIcon()
{
try
{
RegistryKey icoRoot = Registry.ClassesRoot;
string[] keyNames = icoRoot.GetSubKeyNames();
Hashtable iconsInfo = new Hashtable();
foreach (string keyName in keyNames)
{
if (String.IsNullOrEmpty(keyName)) continue;
int indexOfPoint = keyName.IndexOf(".");
if (indexOfPoint != 0) continue;
RegistryKey icoFileType = icoRoot.OpenSubKey(keyName);
if (icoFileType == null) continue;
object defaultValue = icoFileType.GetValue("");
if (defaultValue == null) continue;
string defaultIcon = defaultValue.ToString() + "\\DefaultIcon";
RegistryKey icoFileIcon = icoRoot.OpenSubKey(defaultIcon);
if (icoFileIcon != null)
{
object value = icoFileIcon.GetValue("");
if (value != null)
{
string fileParam = value.ToString().Replace("\"", "");
iconsInfo.Add(keyName, fileParam);
}
icoFileIcon.Close();
}
icoFileType.Close();
}
icoRoot.Close();
return iconsInfo;
}
catch (Exception exc)
{
throw exc;
}
}
+2
source to share
The default icons for the file type , whether or not you have one of these file types, handy are defined in the Windows Registry under
HKEY_CLASSES_ROOT \ type \ DefaultIcon (default)
... but why bother with that when there is a good example of C # code here on VirtualBlackFox in his answer to How to get common file type icons in C #?
+1
source to share