Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Get Files from a Directory Using LINQ

Viewed:  1898 
Posted On:  25/02/2015 09:54:44 
How we can return files from a director in c# using LINQ ? 


string FolderPath = @"D:\AllFiles";
DirectoryInfo di = new DirectoryInfo(FolderPath)

//Get All csv Files
List getAllCSVFiles = di.GetFiles("*.csv")
                  .Where(file => file.Name.EndsWith(".csv"))
                  .Select(file => file.Name).ToList();


//Get All Notepad Files
List getAllCSVFiles = di.GetFiles("*.txt")
                  .Where(file => file.Name.EndsWith(".txt"))
                  .Select(file => file.Name).ToList();

Just pass your file extension and enjoy…


By naci  On  03/04/2015 03:09:05
List .. foreach (var item in getAllCSVFiles) { Console.WriteLine(item); }
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us