About      |       Articles      |      Services      |      Software      |      Contact

Latest Free SharePoint Software

ARB Security Solutions regularly releases free SharePoint software, including WebParts, Client Applications, Framework Extensions, and other Miscellaneous Components.
The most recent freeware is:

Title: Simple SharePoint Rollup WebPart
Date Published: 10/22/2009

Previous Two Free WebPart Releases:

SecureCenter For SharePoint

By SharePoint security integrators, for SharePoint security integrators.

SharePoint Security Assurance Program™

For externally facing SharePoint deployments, security is an acutely important deployment concern. Learn how through daily security scanning, you can ensure external business users and partners that they can collaborate in confidence!

Security Assurance WebPart:



Removing Duplicate SPList Objects From Typed Collections

One of my friends had a slight dilemma in his code this morning where he had a recursive loop, subject and constrained by some limit logic, which iterated through SPList objects in an arbitrary SPWeb and returned a large typed collection of SPList objects. The collection was afterward used for massaging out some specific SPField values, assimilated later by a detached business application.

One difficulty that he was running into was the occurrence of duplicates that were taking place during the generation of the collection. He was questioning if it was workable to inspect and eliminate duplicate SPList objects that occur before returning the final SPList collection.

In order to do this, we of course necessitate a unique identifier for each object, so it makes sense to use the SharePoint generated SPList.ID property which guarantees a unique value. Within the method, we are creating two other collections, a temporary typed dictionary object which will hold the ID values to later act as a guard clause, as well as a provisional SPList collection which will provide return allocation.

C#:
  1. public static List<SPList> CheckAndRemoveDuplicateSPList(IEnumerable<SPList> inputList)
  2. {
  3. Dictionary<Guid, int> tempDictonary = new Dictionary<Guid, int>();
  4. List<SPList> tempListCollection = new List<SPList>();
  5. foreach (SPList list in inputList)
  6. {
  7. if (!tempDictonary.ContainsKey(list.ID))
  8. {
  9. tempDictonary.Add(list.ID, 0);
  10. tempListCollection.Add(list);
  11. }
  12. }
  13. return tempListCollection;
  14. }

That should do the trick!

:)

  • Share/Bookmark

3 Comments »

  1. [...] Removing Duplicate SPList Objects From Typed Collections [...]

    Pingback by Links (7/8/2008) « Steve Pietrek - Everything SharePoint — July 8, 2008 @ 5:03 pm

  2. [...] http://www.sharepointsecurity.com/blog/sharepoint/sharepoint-2007-development/removing-duplicate-splist-objects-from-typed-collections/ [...]

    Pingback by FuzzLinks.com » SharePoint Shelter » Blog Archive » Removing Duplicate SPList Objects From Typed Collections — July 13, 2008 @ 7:15 pm

  3. GroupBy makes this trivial:

    return from l in inputList
    group l by l.ID into g
    select g.First();

    Or in code:
    return inputList.GroupBy(l => l.ID).Select(g => g.First());

    Comment by Keith Dahlby — January 16, 2009 @ 10:10 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment