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.
Loading

Posted Jul 12, 2011, 12:53 AM
var q = from i in new System.IO.DirectoryInfo(@"D:\Projects\").GetFiles("*.gif", System.IO.SearchOption.AllDirectories)
//where i.Name.Contains(fileExt)
select new {i.Name, i.LastAccessTime};//
foreach (var x in q)
{
Console.WriteLine(x.Name.ToString());
}
I tried the above code, it is worked.
I have commented out your where clause and included the search option.
If you give the DriveName like ("D:\") instead of a specific root folder like ("D:\projects\") , you may get UnauthorizedAccessException.
C BPosted Jul 12, 2011, 4:55 PM