C B

C B

  • NA
  • 22
  • 22.1k

IEnumerable 'ListItem' get the Sub Folders

Jul 11 2011 5:17 PM
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)