Compartilhar via


SPList.GetItems method (SPView)

Retorna uma coleção de itens da lista com base no modo de exibição especificado.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaração
Public Function GetItems ( _
    view As SPView _
) As SPListItemCollection
'Uso
Dim instance As SPList
Dim view As SPView
Dim returnValue As SPListItemCollection

returnValue = instance.GetItems(view)
public SPListItemCollection GetItems(
    SPView view
)

Parâmetros

Valor retornado

Type: Microsoft.SharePoint.SPListItemCollection
Os itens de lista especificados pelo modo de exibição.

Exceptions

Exception Condition
ArgumentNullException

view é null (NothingVisual Basic ).

Examples

O exemplo a seguir é um aplicativo de console que usa o modo de exibição "Minhas tarefas" da lista de tarefas para recuperar itens de lista. Após buscar os dados, o aplicativo imprime um relatório simples no console.

Imports System
Imports System.Collections.Specialized
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")
         Using web As SPWeb = site.OpenWeb()

            ' Get data from a list.
            Dim listUrl As String = web.ServerRelativeUrl + "/lists/tasks"
            Dim list As SPList = web.GetList(listUrl)
            Dim view As SPView = list.Views("My Tasks")
            Dim items As SPListItemCollection = list.GetItems(view)

            ' Get a collection of view field names.
            Dim viewFields As StringCollection = view.ViewFields.ToStringCollection()

            ' Print data for each item in the view.
            Dim item As SPListItem
            For Each item In items
               ' Print the value of each view field.
               Dim fieldName As String
               For Each fieldName In viewFields
                  Console.WriteLine("{0} = {1}", fieldName, item(fieldName))
               Next fieldName
               Console.WriteLine()
            Next item

         End Using
      End Using
      Console.ReadLine()
   End Sub
End Module
using System;
using System.Collections.Specialized;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               // Get data from a list.
               string listUrl = web.ServerRelativeUrl + "/lists/tasks";
               SPList list = web.GetList(listUrl);
               SPView view = list.Views["My Tasks"];
               SPListItemCollection items = list.GetItems(view);

               // Get a collection of view field names.
               StringCollection viewFields = view.ViewFields.ToStringCollection();

               // Print data for each item in the view.
               foreach (SPListItem item in items)
               {
                  // Print the value of each view field.
                  foreach (string fieldName in viewFields)
                  {
                     Console.WriteLine("{0} = {1}", fieldName, item[fieldName]);
                  }
                  Console.WriteLine();
               }
            }
         }
         Console.ReadLine();
      }
   }
}

Ver também

Referência

SPList class

SPList members

GetItems overload

Microsoft.SharePoint namespace

GetItems(String, [])