19.4. Querying/Aggregating Data via the API

Developers are often faced with the task of querying for data across multiple SharePoint sites. This task is made a bit easier in MOSS 2007, which ships with a new object that is optimized for cross-site queries: the PortalSiteMapProvider. The Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider is primarily used when there is a need to frequently rerun the same query on data that does not change very often. Microsoft uses this object extensively within MOSS 2007 sites, especially Publishing sites, because it is the fastest way to both generate navigation and retrieve the results for the CQWP. The best part is developers can use this same object in their own custom code!

This object contains three very useful methods:

  • GetCachedListItemsByQuery() — This method retrieves items from a specific list, leveraging special caching techniques.

  • GetChildNodes() — This powerful method retrieves SPWeb and SPListItem objects, including PublishingPage objects. It is very flexible in that developers can specify the types of objects to be returned using the NodeTypes enumeration. The result set does not include the configured Welcome Page, also known as the home page for a SPWeb.

  • GetCachedSiteDataQuery() — This method enables developers to use a preconfigured SPSiteDataQuery object that returns a ADO.NET DataTable object. This method is useful when querying across multiple lists in the same SPWeb.

To use the PortalSiteMapProvider, first get ...

Get Professional SharePoint® 2007 Web Content Management Development: Building Publishing Sites with Office SharePoint Server 2007 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.