This post is migrated from previous hosting provider. There are still some issues with old posts. Please make a comment on this post with any issues.

New release for SPExLib with SharePoint Linq extensions

Tags: SharePoint

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.

No Comments

Comments have been disabled for this content.

About Wictor...

Wictor Wilén is the Nordic Digital Workplace Lead working at Avanade. Wictor has achieved the Microsoft Certified Architect (MCA) - SharePoint 2010, Microsoft Certified Solutions Master (MCSM) - SharePoint  and Microsoft Certified Master (MCM) - SharePoint 2010 certifications. He has also been awarded Microsoft Most Valuable Professional (MVP) for seven consecutive years.

And a word from our sponsors...