public void PopulateBookList(string paramDir, Models.Item rootItem) { if (rootItem == null) { throw new ArgumentNullException(); } rootItem.FullName = paramDir; rootItem.ItemType = Models.ItemType.Folder; DirectoryInfo dir = new DirectoryInfo(paramDir); foreach (DirectoryInfo dirInfo in dir.GetDirectories()) { var item = new Models.Item(); item.Name = dirInfo.Name; rootItem.Children.Add(item); PopulateBookList(dirInfo.FullName, item); } foreach (FileInfo fleInfo in dir.GetFiles().Where(x => AllowedExtensions.Contains(x.Extension)).ToList()) { var item = new Models.Item(); item.Name = fleInfo.Name; item.FullName = fleInfo.FullName; item.ItemType = (Models.ItemType)Enum.Parse(typeof(Extention), fleInfo.Extension.TrimStart('.'), true); rootItem.Children.Add(item); } }
private void UpdateBookList(string path) { DirectoryInfo di = new DirectoryInfo(path); var bookList = new List <Models.Item>(); var rootItem = new Models.Item() { Name = di.Name }; rootItem.ItemType = Models.ItemType.Folder; PopulateBookList(di.FullName, rootItem); bookList.Add(rootItem); DataSource = new ObservableCollection <Models.Item>(bookList); _tvFoundBooks !.ItemsSource = DataSource.OrderBy(a => a.Name); }