I would like to create a method which returns me the newest created file in a Directory in C# with the preferred usage of the Directory.GetFiles() method in the System.IO Namespace. Maybe it's possible to do it also without LINQ to keep it compatible with NET 2.0. Good would be also if the FilePath could be returned as a string not as a File Object if possible The construct should look like below, but how I can see the newest file only?
public static string NewestFileofDirectory(string DirectoryName)
{
foreach(string File in Directory.GetFiles(DirectoryName))
{
if(new FileInfo(File).CreationDate > ???) //here I stuck
{
//interesting what would be here...
}
}
}