2
Answers

IEnumerable 'ListItem' get the Sub Folders

C B

C B

13y
2.6k
1
Hello

How do you get all the sub directories?  The code works fine if you do not include (fileExt, SearchOption.AllDirectories).  As soon as you include (fileExt, SearchOption.AllDirectories) it returns nothing.  it does not through any exceptions i.e. I have put the code in an error handler, 'try/catch'.

   string fileExt = cboFileType.SelectedValue.ToString();//I have been using .jpg from a combo box

 IEnumerable<ListItem> q = from i in new System.IO.DirectoryInfo(SearchDir).GetFiles()//(fileExt,  SearchOption.AllDirectories)
 where i.Name.Contains(fileExt)
 select new ListItem(i.Name, i.LastAccessTime);//
 this.DataContext = q.ToList();
Note: 

I have not included all the code i.e. the code for 'i.Name, i.LastAccessTime'.  Hopefully this will clear up confusion for other newbies like me.

Thanks for your time.











Answers (2)