Sort SPFileCollection by Created Date

Yes, this could be done with a CAML query, but I wanted to keep it simple.

I need to get items created in ascending order (oldest first).

My solution:

SPFileCollection items = web.GetFolder(sLawsonReports).Files;
//sort the files so we get the oldest first
List sortFiles = items.Cast().OrderBy(file => file.TimeCreated).ToList();

Leave a Reply

Your email address will not be published. Required fields are marked *