1

ReadAllFiles(@"../../","names.txt"); I tried this so I am able to read the file.But what I want is to read a file without giving filename and it should read only file with some particular extension like .csv, .xml only

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197

1 Answers1

1

You can read like this. you have to give folder path and the pattern of you want to read the file.You can use GetFiles method also.

string path = "";
foreach (string file in Directory.EnumerateFiles(path, "*.txt"))
{
    string content = File.ReadAllText(file);
}
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197