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

Wictor Wilén

SharePoint Server MVP / Author / MCT / MCTS / MCP / MSc writing about SharePoint and other interesting Microsoft technologies

New release for SPExLib with SharePoint Linq extensions

Posted at 2009-05-30 01:00 by Wictor Wilén in SharePoint with 2 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!
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.
Real Time Web Analytics