If your are using .Net 3.5, you can use LINQ. Use the following code
//This method returns all files in a specific folder with s pecific extention
public System.Collections.Generic.List<FileInfo> GetFiles(string sPath, string sFileExtension) {
DirectoryInfo _dirInfo = new DirectoryInfo(sPath);
return System.Linq.Enumerable.ToList(_dirInfo.GetFiles(string.Format("*{0}", sFileExtension), SearchOption.AllDirectories));
}
//use the below code
//get all files contained in the path supplied by the user
System.Collections.Generic.List<FileInfo> _theFiles = GetFiles(@"c:\myDirectory", ".doc");
//we now have a list of files...next we use LINQ to query the file list and sort in descending order the results by CreationTime
var _files = from file in _theFiles
orderby file.CreationTime descending
select file;
//select the first element
return _files.First();