/// <summary> /// Return the index of the image that has the Shell Icon for the given file/directory. /// </summary> /// <param name="path">The full path to the file/directory</param> /// <returns>The index of the image or -1 if something goes wrong.</returns> public int GetImageIndex(string path) { try { if (Path.HasExtension(path)) { path = Path.GetExtension(path); } else { path = Environment.SystemDirectory; // optimization! give all directories the same image } if (SmallImageCollection.ContainsKey(path)) { return(SmallImageCollection.IndexOfKey(path)); } SmallImageCollection.Add(path, ShellUtilities.GetFileIcon(path, true, true)); if (LargeImageCollection != null) { LargeImageCollection.Add(path, ShellUtilities.GetFileIcon(path, false, true)); } } catch (Exception) { return(-1); } return(SmallImageCollection.IndexOfKey(path)); }
public int GetFolderImageIndex() { string path = Environment.SystemDirectory; // optimization! give all directories the same image try { SmallImageCollection.Add(path, ShellUtilities.GetFileIcon(path, true, true)); if (LargeImageCollection != null) { LargeImageCollection.Add(path, ShellUtilities.GetFileIcon(path, false, true)); } } catch (ArgumentNullException) { return(-1); } return(SmallImageCollection.IndexOfKey(path)); }