kamagra how much to take

Strongly Typed SharePoint List Collections By Template Type

When working with numerous types of lists positioned in a particular web, site, or higher storage medium, it becomes beneficial to build strongly typed SPList collections representing your data source instruments into a class level field for comfortable access and on-demand querying. Refining the approach slightly further, it is even more advantageous to extract template type selection into a paradigm that can be easily manipulated from general interface controls for filter of type if required.

To accomplish this, firstly we are going to build two new classes. One class will contain the static methods, and the other will represent an enumeration that we can switch on that containing the list template types I want to make available.

Firstly, the enumeration:

  1. public enum IncludedListTypes
  2.     {
  3.         All,
  4.         DocumentLibrary,
  5.         Events
  6.     }

The above could observably have a lot more values (it probably should), for like Survey or Announcement lists, but are not included for brevity.

Next, we are going to build two global fields, one providing the class level collection backing field and the other to represent the IncludedListTypes value.

  1. private IncludedListsTypes _type = IncludedListsTypes.All;
  2. private List<SPList> _masterCollection = new List<SPList>();

Moving right along, we are going to build the HydrateListCollectionByTemplate method which will use the previously built enumeration. This will take a ICollection and an SPList object as a parameter. Again, to handle further template types follows an identical paradigm, but not included for brevity.

  1. private void HydrateListCollectionByTemplate(ICollection<SPList> listsList, SPList list)
  2.         {
  3.             switch (_type)
  4.             {
  5.                 case IncludedListsTypes.All:
  6.                     listsList.Add(list);
  7.                     break;
  8.                 case IncludedListsTypes.DocumentLibrary:
  9.                     if (Equals(list.BaseTemplate, SPListTemplateType.DocumentLibrary))
  10.                     {
  11.                         listsList.Add(list);
  12.                     }
  13.                     break;
  14.                 case IncludedListsTypes.Events:
  15.                     if (Equals(list.BaseTemplate, SPListTemplateType.Events))
  16.                     {
  17.                         listsList.Add(list);
  18.                     }
  19.                     break;
  20.             }
  21.         }

Calling this method is pretty straight forward, and naturally is used mostly with recursion. Consider the below, which just gets an SPListCollection from the current context, and hydrates the class level SPList typed collection. Pretty straight forward.

  1. public void PushListsToMasterCollection()
  2.         {
  3.            foreach (SPList curList in SPContext.Current.Web.Lists)
  4.            {
  5.                HydrateListCollectionByTemplate(_masterCollection, curList);
  6.            }
  7.         }
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>