I have 5 different text file inside the Main Folder example
c:\Main
inside Main, i have 5 file (test1.txt, test2.txt. test3.txt, test4.txt and test5.txt)
How to read the latest file?
Reading text file inside the Folder in c#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Apr 8, 2014, 10:15 AM EDT
using System;
using System.IO;
using System.Linq;
class Program
{
static void Main()
{
var di = new DirectoryInfo(@"c:\Main");
string search = "test*.txt";
FileInfo latest = di.GetFiles(search).OrderBy(fi => fi.CreationTime).Last();
string text = File.ReadAllText(latest.FullName);
Console.WriteLine(text);
Console.ReadKey();
}
}
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Apr 8, 2014, 2:05 AM EDT