Step by Step use of PortalSiteMapProvider for cross site and cross list in SharePoint 2010 and SharePoint 2013

The PortalSiteMapProvider is a class which can used to generate the navigation on SharePoint Publishing sites. The Global navigation, the Quick Launch and the Breadcrumb navigation can all be generated with help of the PortalSiteMapProvider. It also provides methods to query sub sites, lists and list items with help of caching.

The main advantage of the PortalSiteMapProvider is that it queries the SharePoint change log to check whether any changes have happened to the data being queried. If yes, then only the incremental changes are fetched and thus the cache is updated accordingly.

However, my tests showed that the PortalSiteMapProvider.GetCachedSiteDataQuery method which is used to get items from multiple sub sites does not maintain an incremental cache and it only fetches the new or updated items when the object cache has expired.

So essentially when querying for items from multiple sites, the CrossListQueryInfo and the PortalSiteMapProvider behave almost similarly.

Here is the sample code for the PortalSiteMapProvider:

SPSiteDataQuery query = new SPSiteDataQuery();
query.ViewFields = “<FieldRef Name=\”Title\” /><FieldRef Name=\”DueDate\” />”;
query.Query = @”<Where>
<And>
<Eq>
<FieldRef Name=’AssignedTo’/>
<Value Type=’User’>” +
SPContext.Current.Web.CurrentUser.Name
+ @”</Value>
</Eq>
<Neq>
<FieldRef Name=’Status’/>
<Value Type=’Choice’>Completed</Value>
</Neq>
</And>
</Where>”;
query.Lists = “<Lists ServerTemplate=\”107\” MaxListLimit=\”0\”/>”; //Tasks Lists
query.Webs = “<Webs Scope=\”Recursive\” />”;
//query.RowLimit = 100;
PortalSiteMapProvider ps = PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode;
PortalWebSiteMapNode pNode = ps.FindSiteMapNode(curWeb.ServerRelativeUrl) as PortalWebSiteMapNode;
DataTable results = ps.GetCachedSiteDataQuery(pNode, query, SPContext.Current.Web);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s