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:



Multiple SPListItemCollection Query With SPFieldLookupValue

While SPList objects do not sustain true relational integrity due to the inherent nature of unstructured SharePoint data storage (in the current version at least), it is common within business applications to use Lookup field types are leveraged to build weak references between SharePoint lists. As such, typed collection queries become important, combining LINQ with method chaining allows us to write succinct SPListItem returns.

Firstly, let's make some requisite test proxy objects:

C#:
  1. SPWeb curWeb = SPContext.Current.Web;
  2. SPList list1 = curWeb.Lists["My First List"];
  3. SPList list2 = curWeb.Lists["My Second List"];

Now, let’s assume the following business requirement. I want to loop through list1, and match a returned SPField value to a string condition defined by a literal. Subsequently, the return will be used on the list2 SPList object within the Where clause. This is considered in the following code snippet:

C#:
  1. var resultSet  = list1.Items.Cast<SPListItem>()
  2. .Where(i => Equals (String.Compare(i["Property To Match #1"].ToString(), "Example String Literal"), 0))
  3. .SelectMany(x => list2.Items.Cast<SPListItem>()
  4. .Where(i => Equals(String.Compare(new SPFieldLookupValue(x["Client"].ToString()).LookupValue, (string) i["Property To Match #2"]), 0)));

The above code is arguable that the second casting operation for the typed collection build should be broken out into a separate variable before the call and replacing the Cast statement within SelectMany with the result of the call using ToList to forces immediate execution. Meh. :)

  • Share/Bookmark

Related posts:

  1. Using Regular Expressions To Build SPList Collections
  2. Customizing ListFormWebPart URL Returns
  3. Using Regular Expressions For SharePoint List Collection Queries
  4. Using Generics To House SharePoint Objects
  5. Best Practice: Don’t Iterate SPListItems for IQueryable Support

5 Comments »

  1. [...] Multiple SPListItemCollection Query With SPFieldLookupValue [...]

    Pingback by Links (4/30/2009) « Steve Pietrek - Everything SharePoint and Office — April 30, 2009 @ 4:47 pm

  2. [...] Join SharePoint Lists with LINQ April 30, 2009 — Keith Dahlby I just read yet another post by Adam Buenz that got me thinking, this time about querying multiple SharePoint lists. Here’s the code he came up with: [...]

    Pingback by Join SharePoint Lists with LINQ « Solutionizing .NET — April 30, 2009 @ 10:03 pm

  3. Excellent! Much more succinct code then foreach loops over SPListItems.

    Comment by Kirk C. — May 5, 2009 @ 7:50 am

  4. Pretty reasonable, but debugging with it is difficult without excessive use of the immediate window in VS.NET.

    Comment by Matt T. — May 5, 2009 @ 7:57 am

  5. This is pretty good, but debugging it is difficult to look at the collection building at run-time. I might use more local variables…but the end result would be the same…

    Comment by James Fortner — May 8, 2009 @ 7:34 am

RSS feed for comments on this post. TrackBack URL

Leave a comment