/// <summary> /// Gets all files from the given path. /// </summary> /// <param name="selectedImagePath"></param> private List <FileInfoWithIcon> GetFiles(string selectedImagePath) { List <FileInfoWithIcon> fiwiList = new List <FileInfoWithIcon>(); foreach (var fileName in new DirectoryInfo(selectedImagePath) .GetFiles() // Skipping hidden and system files. .Where(f => !f.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) .Select(x => x.FullName).ToList()) { var extractAssociatedIcon = Icon.ExtractAssociatedIcon(fileName); // Making FileInfoWithIcon with all the files and their icons. if (extractAssociatedIcon != null) { var fai = new FileInfoWithIcon { FileInfo = new FileInfo(fileName), ImageSource = Imaging.CreateBitmapSourceFromHIcon( extractAssociatedIcon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()) }; fiwiList.Add(fai); } } return(fiwiList); }
/// <summary> /// Gets all dictionaries from the given path. /// </summary> /// <param name="selectedImagePath"></param> private List <FileInfoWithIcon> GetDirecotries(string selectedImagePath) { List <FileInfoWithIcon> fiwiList = new List <FileInfoWithIcon>(); foreach (var fileName in Directory.GetDirectories(selectedImagePath) .Where(d => !new DirectoryInfo(d).Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System))) { // Dictionaries do not have associated icon. // Other solution: Using the native SHGetFileInfo function. var uri = new Uri("pack://application:,,,/Resources/folder.png"); var fai = new FileInfoWithIcon { FileInfo = new FileInfo(fileName), ImageSource = new BitmapImage(uri) }; fiwiList.Add(fai); } return(fiwiList); }