SPList.GetItems method (String[])

Returns a collection of items from the list but includes only the specified field values.

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

public SPListItemCollection GetItems(
	params string[] fields


Type: []

A variable number of field names for which to get values. If all fields should be retrieved, use the Items property instead.

Return value

Type: Microsoft.SharePoint.SPListItemCollection
A collection of list items.


fields is null .

This method creates a new SPQuery object from the specified fields and calls the GetItems(SPQuery) method with that new object to get the items.

This method is more efficient than accessing the Items property because it only fetches the values for the specified fields.

The following example is a console application that specifies field values to return in items retrieved from a list. After fetching the data, the application prints a simple report to the console.

using System;
using Microsoft.SharePoint;

namespace Test
   class ConsoleApp
      static void Main(string[] args)
         using (SPSite site = new SPSite("http://localhost"))
            using (SPWeb web = site.OpenWeb())
               // Get data from a list.
               string listUrl = web.ServerRelativeUrl + "/lists/tasks";
               SPList list = web.GetList(listUrl);
               SPListItemCollection items = list.GetItems("LinkTitle", "AssignedTo", "DueDate", "Status");

               // Print a report header.
               Console.WriteLine("{0,-25}  {1,-20}  {2,-25}  {3}",
                  "Assigned To", "Task", "Due Date", "Status");

               // Print the details.
               foreach (SPListItem item in items)
                  Console.WriteLine("{0,-25}  {1,-20}  {2,-25}  {3}",
                     item["AssignedTo"], item["LinkTitle"], item["DueDate"], item["Status"]);