This topic has not yet been rated - Rate this topic

PortalSiteMapProvider.GetCachedListItemsByQuery Method

Gets a collection of PortalListItemSiteMapNode objects that represent the list items returned by a specified query.

Namespace:  Microsoft.SharePoint.Publishing.Navigation
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)
public SiteMapNodeCollection GetCachedListItemsByQuery(
	PortalWebSiteMapNode webNode,
	string listName,
	SPQuery query,
	SPWeb contextWeb
)

Parameters

webNode
Type: Microsoft.SharePoint.Publishing.Navigation.PortalWebSiteMapNode
The PortalWebSiteMapNode object that represents the Web site that contains the list of interest.
listName
Type: System.String
The name of the list of interest.
query
Type: Microsoft.SharePoint.SPQuery
The SPQuery object to run against the list.
contextWeb
Type: Microsoft.SharePoint.SPWeb
The SPWeb object that exists within the context of a particular user. For example, this parameter can specify the SPContext.Current.Web object for the current user.

Return Value

Type: System.Web.SiteMapNodeCollection
A SiteMapNodeCollection object that contains PortalListItemSiteMapNode objects that represent the items returned by the query.

The contextWeb parameter is used to determine the correct list items to return.

The following example references the following assemblies:

  • System.dll

  • System.Data.dll

  • System.Xml.dll

  • System.Web.dll

  • System.Configuration.dll

  • Microsoft.SharePoint.dll

  • Microsoft.SharePoint.Library.dll

  • Microsoft.SharePoint.Publishing.dll

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;

using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.Navigation;


namespace Microsoft.SDK.SharePointServer.Samples

{

    class GetCachedListItemSample

    {

        // Get a list of the created dates for the list items returned by the 
        // given query when run against the cache.
        // Note: You must call this method from within an
        // HttpContext object (that is, HttpContext.Current must return a
        // valid HttpContext)

        public static List<DateTime>GetCachedListItemCreatedDates(
            string serverRelativeWebUrl, string listName, SPQuery query)

        {

            List<DateTime> createdDates = null;

             // Get a reference to the current navigation provider 
            // (that is, the one that doesn't HTML-encode titles).

            PortalSiteMapProvider portalProvider = 
              PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode;

            // Look up the node for the given Web site URL.

            PortalWebSiteMapNode webNode = 

                portalProvider.FindSiteMapNode(serverRelativeWebUrl) as PortalWebSiteMapNode;

            if (webNode != null)

            {

                // Retrieve nodes representing the list items returned from the 
                // given query, performed on the given list.

                SiteMapNodeCollection listItemNodes = portalProvider.GetCachedListItemsByQuery(

                        webNode, listName, query, SPContext.Current.Web);

                createdDates = new List<DateTime>(listItemNodes.Count);
                foreach (PortalListItemSiteMapNode listItemNode in listItemNodes)

                {

                    // Use the indexer to access a particular field, and add the value to
                    // the list.

                    createdDates.Add((DateTime)listItemNode[SPBuiltInFieldId.Created]);

                }

            }

            // Return the list of titles.

            return createdDates;

        }
    }
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Do not set ViewFields of the SPQuery
Do not set the ViewFields property of the SPQuery object. If you do, you won't get any items.
PortalSiteMapProvider perform better then all List data access methods
The PortalSiteMapProvider class is one of the best performing List data access methods.$0 $0 PortalSiteMapProvider class is going to be most useful if the data you are retrieving is not significantly different over time. If you are trying to frequently retrieve different data sets, the PortalSiteMapProvider class will incur the overhead of constantly reading from the database, inserting data into the cache and then returning it from the method call$0 $0 The advantage of the PortalSiteMapProvider class is when it can read data directly from the cache.$0 $0 The amount of memory the PortalSiteMapProvider class has available to use may be somewhat constrained. It uses the site collection object cache to store data; by default, the object cache is only 100 megabytes (MB). $0 $0 for More information on Microsoft performed performance testing against Microsoft® Office SharePoint® Server 2007 read this doc $0http://office.microsoft.com/download/afile.aspx?AssetID=AM102377231033 $0$0 $0 $0 $0 $0