Posted by Adam Buenz
One of my friends just asked me a rather distinctive question. What if I wanted to build a typed collection of SPList objects by passing in a SharePoint web (SPWeb) and a pattern to match the list by (string) into some arbitrary method?
In order to do this, we can presume since the pattern is being passed in as a parameter that in some additional scene it is being constructed and is well-formed. Therefore, we can do a uncomplicated regular expression match leveraging the list title and the pattern. Following, test the result of the match, ensuring that it coordinates to success. We then return the collection if the count is higher than 0, otherwise just return null.
C#:
-
public static List<SPList> PoolListsByExpression(string pattern, SPWeb web)
-
{
-
foreach (SPList list in web.Lists)
-
{
-
if (Regex.Match(list.Title, pattern).Success)
-
{
-
tempListCollection.Add(list);
-
}
-
}
-
if (tempListCollection.Count> 0)
-
{
-
return tempListCollection;
-
}
-
return null;
-
}











July 15th, 2008 at 5:49 pm
[...] Using Regular Expressions To Build SPList Collections [...]
October 8th, 2008 at 1:55 am
[...] 2008-10-08 - Using Regular Expressions To Build SPList Collections saved by ajonser2008-10-03 - Coin slots saved by sad12672008-10-02 - Data Center Security - 5 Critical Requirements saved by Osmosis2008-09-30 - More SQL saved by soviepills2008-09-27 - Multi-mold high frequency PWM controller UCC39421/2 and application saved by waven152008-09-14 - Even More GNUMP3d saved by TMF72008-09-11 - The Default Ruby Dial Plan Demystified saved by qdiddy10q2008-09-07 - Redirects: Good, Bad & Conditional saved by jasonscheirer [...]