SharePoint Cross List Queries in a custom UserControl

Tobias Zimmergren
Tobias Zimmergren
💡🤖TIP: Check out the guidance for AI adoption on Azure!

Author: Tobias Zimmergren
Url: http://www.zimmergren.net

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:

crossqueries1

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

crossqueries2

crossqueries3

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.

SharePointQueries

Tobias Zimmergren Twitter

Hi, I'm Tobias! 👋 I write about Microsoft Azure, security, cybersecurity, compliance, cloud architecture, Microsoft 365, and general tech!

Reactions and mentions


Hi, I'm Tobias 👋

Tobias Zimmergren profile picture

Find out more about me.

Recent comments

Mastodon