kamagra how much to take

Using Regular Expressions To Build SPList Collections

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.

  1. public static List<SPList> PoolListsByExpression(string pattern, SPWeb web)
  2. {
  3. List<SPList> tempListCollection = new List<SPList>();
  4. foreach (SPList list in web.Lists)
  5. {
  6. if (Regex.Match(list.Title, pattern).Success)
  7. {
  8. tempListCollection.Add(list);
  9. }
  10. }
  11. if (tempListCollection.Count > 0)
  12. {
  13. return tempListCollection;
  14. }
  15. return null;
  16. }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>