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
Asked
Active
Viewed 801 times
1
-
Have a look at https://stackoverflow.com/questions/3152157/find-a-file-with-a-certain-extension-in-folder – SBFrancies Jun 02 '20 at 10:49
1 Answers
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