SPList.Items property

Gets an unfiltered collection of all items in the list.

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

public SPListItemCollection Items { get; }

Property value

Type: Microsoft.SharePoint.SPListItemCollection
An SPListItemCollection object that represents the collection of items.

The Items property returns all the files in a document library, including files in subfolders, but not the folders themselves. In a document library, folders are not considered items.

When you call the Items property, it returns an instance of an SPListItemCollection object that does not contain any data, but on first access to an item from the collection, the entire collection object is filled with data. Consequently, to improve performance it is recommended that you assign the items returned by Items to an SPListItemCollection object if you must iterate the entire collection, as seen in the example. It is best practice is to use one of the GetItem* methods of SPList to return a filtered collection of items.

The following example displays the items of a Project list within a label. The example assigns the items that are returned by the Items property to an SPListItemCollection object and then iterates through the collection. The example does not use oList.Items[i] within the for loop.

using (SPWeb oWebsite = new SPSite("http://Server/sites/SiteCollection").OpenWeb())

    SPList oList = oWebsite.Lists["Projects"];

    SPListItemCollection collItem = oList.Items;

    for (int i = 0; i < oList.ItemCount; i++)
        string itemName = collItem[i].Name;

        Label1.Text += itemName + "<BR>";