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.
- public static List&<SPList> GetListFromCollectionByName(string pattern, SPListCollection listCollection)
- var list = new List<SPList>();
- foreach (SPList iteratedList in listCollection)
- if (Regex.Match(iteratedList.Title, pattern).Success)
- return list.Count > 0 ? list : null;