Add to My Yahoo! | Google Reader or Homepage | Add to Windows Live | Add to Windows Live Alerts

Wictor Wilén

Microsoft Certified Master (MCM) - SharePoint 2010 | Microsoft Most Valuable Professional (MVP) - SharePoint Server MVP | Author

New release for SPExLib with SharePoint Linq extensions

Posted at 2009-05-30 01:00 by Wictor Wilén in SharePoint with 4 comments.

I'm really glad that we have managed to get a really nice release of the SharePoint Extensions Lib, SPExLib, out. This brand new release (12.0.0.0) has significantly been improved since the first release a couple of weeks ago.

Keith Dahlby has made some really nice Linq extensions for SharePoint which is available in this release. These extensions are also IDisposable safe when using on SPWeb and SPSite collections.

By referencing the SPExLib.dll and include the namespaces you can easily write code like this (taken directly from one of my current projects):

   1: SPList regions = web.Lists["Regions"];         
   2: regions.GetItems("<Where><Eq><FieldRef Name='Customer'/><Value Type='Lookup'>{0}</Value></Eq></Where>"
   3:                     .FormatWith(lookupValue)
   4:                 )
   5:            .ForEach<SPListItem>(
   6:                     item => ddlRegion.Items.Add(new ListItem(item["Title"].ToString(), item.ID.ToString()))
   7:             );

As you can see the sample uses a number of extension methods; SPList.GetItems() can accept a CAML query directly, System.String has a FormatWith method, the SPListItemCollection has a ForEach method.

Download it and try it out, you will find yourself more productive!

Have a nice weekend.

Comments and trackbacks

#  software developers by software developers
Screenshot from websnpr Hey, that was interesting, I downloaded it and used it and it is much better than the old version Thanks for writing about it
#  @software developers by Wictor
Screenshot from websnpr Thank you!
#  RowLimit for GetItems by Consultant
Screenshot from websnpr I ran into a project where SPExLib (12.0.0.1) was used quite a lot. Many queries used the extension method GetItems(this SPList source, string whereQuery). The problem that I see with this method is that it defaults to a RowLimit of 0x7FFFFFFF. This may result in quite large queries. An overload with the possibility to define a RowLimit might be handy.
#  Useful Links 321 by Trackback
Screenshot from websnpr Useful Links 321
Make a comment on this post:
Subject:  

Your name:  
Your Url:  
Note: submissions may have to be approved before being visible, so don't submit your comment multiple times.