string FolderPath = @"D:\AllFiles";DirectoryInfo di = new DirectoryInfo(FolderPath)
//Get All csv FilesList getAllCSVFiles = di.GetFiles("*.csv") .Where(file => file.Name.EndsWith(".csv")) .Select(file => file.Name).ToList();
//Get All Notepad FilesList getAllCSVFiles = di.GetFiles("*.txt") .Where(file => file.Name.EndsWith(".txt")) .Select(file => file.Name).ToList();
Just pass your file extension and enjoy…