0

I am trying to get files from a directory where, latest created files or modified files should be on top of the grid view, I tried this OrderByDescending but not helpful

string[] filePaths = Directory.GetFiles(Server.MapPath("~/Results/"));
List<Thing> lst = new List<Thing>();
foreach (string filePath in filePaths)
{
    string filename = Path.GetFileNameWithoutExtension(filePath);
    string dateformat = filename.Substring(0, 10);
    lst.Add(new Thing() { FileDate = filename.Split('_')[0], FileName = 
    filename.Split('_')[1], FilePath = filePath });
}
GridView1.DataSource = lst;
GridView1.DataBind();
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Web Funda
  • 41
  • 1
  • 6
  • Hint: You can find the creation time using [`FileInfo`](https://learn.microsoft.com/en-us/dotnet/api/system.io.fileinfo?view=net-5.0). Also, you can use the `GetFiles` method of [`DirectoryInfo`](https://learn.microsoft.com/en-us/dotnet/api/system.io.directoryinfo.getfiles?view=net-5.0) to get an array of `FileInfo`. – ProgrammingLlama Jun 24 '21 at 06:25
  • Does [File.GetLastWriteTimeUtc](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.getlastwritetimeutc) help? – Klaus Gütter Jun 24 '21 at 06:25
  • `I tried this OrderByDescending but not helpful` Show us that attempt. – mjwills Jun 24 '21 at 06:27

0 Answers0