PortalSiteMapProvider.GetCachedListItemsByQuery

PortalSiteMapProvider.GetCachedListItemsByQuery

With MOSS 2007 or SharePoint Server 2010 you can use the PoraltSiteMapProvider of the Microsoft.SharePoint.Publishing.dll assembly to retrieve cached listitems.

   1: PortalSiteMapProvider ps = PortalSiteMapProvider.WebSiteMapProvider;
   2: var pNode = ps.FindSiteMapNode(web.ServerRelativeUrl) as PortalWebSiteMapNode;
   3: var query = new SPQuery
   4:                {
   5:                   Query = "<Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Neq></Where>"
   6:                };
   7: SiteMapNodeCollection quoteItems = ps.GetCachedListItemsByQuery(pNode, "Top Seiten", query, web);

In my case, I didn’t need any special where clause. I wanted to retrieve all items, so I left the Query property  empty. And because I needed only three columns, I specified the ViewFields property of the SPQuery object.

Bad idea. The query failed hard and fast 🙂

Conclusion:

If you use the GetCachedListItemsByQuery method, do not specify the ViewFields property of the SPQuery and configure a query. Even if it returns all items of the list!

Leave a Reply