Search This Blog

Tuesday, May 17, 2011

Sorting SPListItemCollection using LINQ

Using LINQ to sort SPLiStItemCOllection:

SPList objRelationShipList;
SPListItemCollection objRelationShipListItems;
objRelationShipList = SPContext.Current.Web.Lists["ListName"];
objRelationShipListItems = objRelationShipList.Items;
List<SPListItem> results = (from SPListItem item in objRelationShipListItems           
                            orderby item.ID
                            select item).ToList();
foreach(SPListItem in results)
{
....
}

Cheers

2 comments: