Поделиться через


Метод PortalSiteMapProvider.GetCachedListItemsByQuery

Возвращает коллекцию объектов PortalListItemSiteMapNode , представляющих список элементов, возвращенных с заданным запросом.

Пространство имен:  Microsoft.SharePoint.Publishing.Navigation
Сборка:  Microsoft.SharePoint.Publishing (в Microsoft.SharePoint.Publishing.dll)

Синтаксис

'Декларация
Public Function GetCachedListItemsByQuery ( _
    webNode As PortalWebSiteMapNode, _
    listName As String, _
    query As SPQuery, _
    contextWeb As SPWeb _
) As SiteMapNodeCollection
'Применение
Dim instance As PortalSiteMapProvider
Dim webNode As PortalWebSiteMapNode
Dim listName As String
Dim query As SPQuery
Dim contextWeb As SPWeb
Dim returnValue As SiteMapNodeCollection

returnValue = instance.GetCachedListItemsByQuery(webNode, _
    listName, query, contextWeb)
public SiteMapNodeCollection GetCachedListItemsByQuery(
    PortalWebSiteMapNode webNode,
    string listName,
    SPQuery query,
    SPWeb contextWeb
)

Параметры

  • listName
    Тип: System.String

    Имя списка интересов.

  • contextWeb
    Тип: Microsoft.SharePoint.SPWeb

    Объект SPWeb , который существует в контексте определенного пользователя. Например этот параметр можно указать объект SPContext.Current.Web для текущего пользователя.

Возвращаемое значение

Тип: System.Web.SiteMapNodeCollection
Объект SiteMapNodeCollection , который содержит объекты PortalListItemSiteMapNode , представляющие элементы, возвращенные запросом.

Замечания

Параметр contextWeb используется для определения надлежащего списка элементов для возврата.

Примеры

Следующий пример ссылается на следующие сборки:

  • 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;

        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Web

Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Navigation

Imports Microsoft.SharePoint.Publishing
Imports Microsoft.SharePoint.Publishing.Navigation


Namespace Microsoft.SDK.SharePointServer.Samples


    Friend 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 Shared Function GetCachedListItemCreatedDates(ByVal serverRelativeWebUrl As String, ByVal listName As String, ByVal query As SPQuery) As List(Of Date)


            Dim createdDates As List(Of Date) = Nothing

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

            Dim portalProvider As PortalSiteMapProvider = PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode

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

            Dim webNode As PortalWebSiteMapNode = TryCast(portalProvider.FindSiteMapNode(serverRelativeWebUrl), PortalWebSiteMapNode)

            If webNode IsNot Nothing Then


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

                Dim listItemNodes As SiteMapNodeCollection = portalProvider.GetCachedListItemsByQuery(webNode, listName, query, SPContext.Current.Web)

                createdDates = New List(Of Date)(listItemNodes.Count)
                For Each listItemNode As PortalListItemSiteMapNode In listItemNodes


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

                    createdDates.Add(CDate(listItemNode(SPBuiltInFieldId.Created)))

                Next listItemNode

            End If

            ' Return the list of titles.

            Return createdDates

        End Function
    End Class
End Namespace

См. также

Справочные материалы

PortalSiteMapProvider класс

Элементы PortalSiteMapProvider

Пространство имен Microsoft.SharePoint.Publishing.Navigation

PortalSiteMapProvider