in SharePoint, SharePoint 2007

Simple way to use LINQ with SharePoint ItemCollections

Here is a simple way to make use of LINQ with SharePoint item collections, for example, with List Items

SPListItemCollection listPages = pagesList.Items;
var latestPages = listPages.Cast<SPListItem>().Where(p => p.Name != defaultPageName);

And this becomes really cool if you use with Dynamic LINQ

var latestPages = listPages.Cast<SPListItem>()
                                .Where(p => p.Name != defaultPageName)
                                .OrderByDescending(p => p[Constants.Modified].ToString())

How cool is that? 🙂

Write a Comment


Time limit is exhausted. Please reload the CAPTCHA.