Compartilhar via


SPList.Items Property

Gets an unfiltered collection of all items in the list.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public ReadOnly Property Items As SPListItemCollection
    Get
'Usage
Dim instance As SPList
Dim value As SPListItemCollection

value = instance.Items
public SPListItemCollection Items { get; }

Property Value

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

Remarks

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.

Examples

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 oWebsite As SPWeb = New SPSite("http://lsspf4719/sites/TestWebs").OpenWeb()
    
    Dim oList As SPList = oWebsite.Lists("Projects")
    
    Dim collItem As SPListItemCollection = oList.Items
    
    For i As Integer = 0 To oList.ItemCount - 1
        Dim itemName As String = collItem(i).Name
       
        Label1.Text += itemName & "<BR>"
    Next
End Using
using (SPWeb oWebsite = new SPSite("https://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>";

    }
}

See Also

Reference

SPList Class

SPList Members

Microsoft.SharePoint Namespace