Filter a datatable to get the latest file that is uploaded in a site

EDIT: Ignore the stuff I posted and just check out the link below. It’s a great example of how to do it with a good explanation of how it works as well.

Start by reading the entire excel sheet to a datatable (i’ll call it dt1)

Next you should make sure the datatable is reading the column named “published” as a datetime by using datetime.Parse or datetime.ParseExact.

Finally, for the actual filter/comparison you could do it multiple ways. I’d recommend converting dt1 to enumerable and using the .OrderByDescending() function. You could also use an Enumurable.Max(), or you could use dt1.Select(), or you could loop through each row and compare to the current highest max. All would work

You could also combine the parsing and the functions into one single line if you choose so it’d look something like this (note, it’s a bit messy and I haven’t actually tried it out myself, just typing it out):

dt1.AsEnumerable.Where(Function(x) DateTime.TryParse(x(“published”).ToString, Nothing)).OrderByDescending(Function(x) If(DateTime.TryParse(x(“published”).ToString, Nothing), DateTime.ParseExact(x(“published”).ToString,"dd.MM.yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture), DateTime.MinValue)).First