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

Get Files from a Directory Using LINQ

Article:
Viewed:  814 
Posted On:  25/02/2015 09:54:44 
How we can return files from a director in asp.net 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…

 

  Comment:
 
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