How to get files using C Sharp

Hi,

How to get file names from the directory using C#?

RajKumar | Answered# (13)
Reply For This Question
Answer(s) Posted
How to get files using C Sharp

namespace

using System.IO;

Code to get filename with full directory path:

string[] files = Directory.GetFiles(path, filter);

After getting list of files. Iterate through the collection to get only file name

  for (int i = 0; i < files.Length; i++)

{
      var fileName =  Path.GetFileName(files[i]);

      Console.WriteLine(fileName);

}

 

 

Raj Kumar | Answered# (13)
Post Your Answer
   Please login to post your answer.
  Member Login
  Email Address  
  Password  
   Sign Up?  
  Privacy   Terms Of Use   Contact Us
© 2016 Developerin.Net. All rights reserved.
Trademarks and Article Images mentioned in this site may belongs to Microsoft and other respective trademark owners.
Articles, Tutorials and all other content offered here is for educational purpose only and its author copyrights.