kamagra how much to take

Typed Dictionary With SharePoint Web Titles And Typed SPListItem Collection

I use this technique a lot when I am building some aggregation components in custom applications. The goal of the method is to provide a static way to constrcut typed Dictionary collections where the SPWeb.Title acts as the Key, and a typed SPListItem collection is the Value. While there will obviously only exist one unique instance of the SPWeb.Title key, additional SPListItem‘s should be appended to their respective key.

In the below, the ItemConsumeAndStructure method has a return type of Dictionary<string, List<SPListItem>>, in accordance with the design goals set forward in the above. There are two parameters being consumed, an IEnumerable<SPList> that represents the set of SPList objects that should be subject to the loop, and a SPView object that’s the view we want to restrict the SPListItemCollection to. Firstly, a temporary dictionary used for the return is built, subsequently a loop will execute against the typed collection hydrating a SPListItemCollection refined using the aforementioned SPView parameter. Recurring through that collection, the dictionary is checked with the SPListItem.SPWeb.Title property is already a key present in the dictionary, and if it’s not instantiate a new List<SPListItem> collection. Adding the SPListItem otherwise to the pre-existing key SPListItem collection completes the requirement.

  1. public static Dictionary<string, List<SPListItem>> ItemConsumeAndStructure(IEnumerable<SPList> listofLists, SPView view)Q
  2.         {
  3.             var dictionary = new Dictionary<string, List<SPListItem>>();
  4.             try
  5.             {
  6.                 foreach (SPList list in listofLists)
  7.                 {
  8.                     SPListItemCollection items = list.GetItems(view);
  9.                     foreach (SPListItem item in items)
  10.                     {
  11.                         if (!dictionary.ContainsKey(item.Web.Title))
  12.                         {
  13.                             dictionary[item.Web.Title] = new List<SPListItem>();
  14.                         }
  15.                         dictionary[item.Web.Title].Add(item);
  16.                     }
  17.                 }
  18.             }
  19.             catch (Exception exception)
  20.             {
  21.  
  22.             }
  23.             return dictionary;
  24.         }
share save 171 16 Typed Dictionary With SharePoint Web Titles And Typed SPListItem Collection

4 Comments

  1. Jonas says:

    don’t forget to remove the try catch….

  2. adam says:

    Well, it SHOULD be in there, it’s just generally a developer choice what happens in the latter.

  3. Joe says:

    Hi.
    Thanks alot, I spent a day to find a code that allow me to read data from sharepoint view, and I found here finally,
    thank you so much

  4. adam says:

    np!!

Trackbacks/Pingbacks

  1. Links (9/7/2009) « Steve Pietrek – Everything SharePoint - [...] Typed Dictionary With SharePoint Web Titles And Typed SPListItem Collection [...]

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=""> <strike> <strong>