Company      |       Articles & Research      |      Services      |      Software      |      Contact

Using Regular Expressions For SharePoint List Collection Queries

It’s pretty common that when working heavily with SharePoint based applications that make heavy use of numerous SharePoint lists that you often have to query down into SPListCollection collections using some sort of search criteria. The below example builds a typed collection consuming a regular expression pattern specified as a string literal and an SPListCollection, using a Regex.Match in order to build a typed SPList collection.

C#:
  1.         public static List&<SPList> GetListFromCollectionByName(string pattern, SPListCollection listCollection)
  2.         {
  3.             var list = new List<SPList>();
  4.             foreach (SPList iteratedList in listCollection)
  5.             {
  6.                 if (Regex.Match(iteratedList.Title, pattern).Success)
  7.                 {
  8.                     list.Add(iteratedList);
  9.                 }
  10.             }
  11.             return list.Count> 0 ? list : null;
  12.         }

share save 171 16 Using Regular Expressions For SharePoint List Collection Queries

Related posts:

  1. Using Regular Expressions To Build SPList Collections
  2. Strongly Typed SharePoint List Collections By Template Type
  3. Typed Dictionary With SharePoint Web Titles And Typed SPListItem Collection
  4. Removing Duplicate SPList Objects From Typed Collections
  5. How To Wire A SharePoint List To A Telerik RadScheduler

1 Comment »

  1. [...] Using Regular Expressions For SharePoint List Collection Queries [...]

    Pingback by Links (9/7/2009 « Steve Pietrek – Everything SharePoint) — September 7, 2009 @ 4:10 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment