SharePoint Cross List Queries in a custom UserControl
Author: Tobias Zimmergren
I got the question last week weather it’s possible to get items from all lists of gathered and displayed on one page.
This is – like most things – possible in SharePoint without any greater efforts. With something called Queries we can use the object model to query SharePoint and get a result quite painlessly.
To demonstrate a very simple example, I’ve created a very small usercontrol (for use with Jan Tielen’s SmartPart) that looks like this:
This code will combine all the items in all of the TaskLists on the current SiteCollection and display them in a simple GridView as seen above in the screenshot.
Code for the Cross List Query UserControl
Simple enough, huh?
Of course you can create webparts, usercontrols, application pages, or any other type of application to interact with the object model in this way. I chose to do it using a UserControl for the ease of deployment, testing, development and demonstration.
For your conveniance I’ve uploaded the UserControl (.zip) here so you can download it.