I have a ListBox, filled by DirectoryInfo:
FileInfo[] files = (new DirectoryInfo(Program.pathtofiles())).GetFiles();
for (int i = 0; i < (int)files.Length; i++)
{
FileInfo fileName = files[i];
this.ListBox.Items.Add(fileName);
}
one Item looks like:
DATA_department_08-09-2017.pdf
So my Question is how to sort the Itmes in the ListBox by the Date at the end? I know there are some sort-functions for the ListBox but they donĀ“t work for me.
So the file-name contains three tokens and the last is the date, you can use this LINQ approach:
If you want to reorder the list-items without reading from file-system:
If you want last dates first use
OrderByDescending
.