KMN
KMN

Reputation: 306

Sitecore Item/Subitem sorting with Linq

How would one go about sorting a list of Sitecore subitems using Linq with the following method, AND converting/casting the "sortedlist" back to Sitecore.Data.Items.Item[]:

...
Sitecore.Data.Items.Item[] subitems = current.SelectItems(query);
var sortedList = (from entry in subitems orderby entry.Fields["Title"].Value ascending select entry);  
...  

Note: I have unsuccessfully attempted to sort it in the query.

Upvotes: 0

Views: 2302

Answers (1)

Marek Musielak
Marek Musielak

Reputation: 27132

You don't need the .Field from the items. Just use the value directly using ["Title"], e.g.:

Sitecore.Data.Items.Item[] subitems = current.SelectItems(query);
Sitecore.Data.Items.Item[] sorted = subitems.OrderBy(i => i["Title"]).ToArray();

Upvotes: 1

Related Questions