I use the below code to get files with different extensions in the folder by LINQ, but no file is found.
var dirInfo = new DirectoryInfo(Application.StartupPath + "\\TextDocument\\");
var filteredFiles = (from fileDir in dirInfo.GetFiles()
where (fileDir.Extension == "*.jpg" || fileDir.Extension == "*.rtf")
select fileDir).ToList();
foreach (var item in filteredFiles)
{
listBox1.Items.Add(item);
}
I get filteredFiles.count = 0
in the foreach
loop. What's wrong in this code?