SPListItemCollection Class
The SPListItemCollection class represents a collection of SPListItem objects.
System.Object
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.SPListItemCollection
Public Methods
The following table shows the public methods of the SPListItemCollection class and a brief description of each.
Name | Description |
---|---|
Add | Creates an item but requires the Update method to actually add the item to the list. |
Delete | Deletes the item at the specified index in the collection. |
DeleteItemById | Deletes the item with the specified integer ID from the collection. |
GetDataTable | Returns the list item collection as a data table. |
GetItemById | Returns the item with the specified integer ID from the collection. |
ReorderItems | Reorders items in the list. |
Public Properties
The following table shows the public properties of the SPListItemCollection class, the data type of each property, and a brief description of each.
Name | Data Type | Description |
---|---|---|
Count | Int32 | Gets the number of list items in the collection. |
Item(Int32) | Microsoft.SharePoint.SPListItem | Gets the list item at the specified index in the collection. |
List | Microsoft.SharePoint.SPList | Gets the parent list of the collection. |
ListItemCollectionPosition | Microsoft.SharePoint.SPListItemCollectionPosition | Gets an object used to obtain the next set of rows in a paged view of a list. |
NumberOfFields | Int32 | Gets the number of fields that are represented in the collection. |
Xml | String | Gets all the data in the collection in XMLDATA format. |
XmlDataSchema | String | Gets the schema that defines the XML returned by the Xml property. |
Thread Safety
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.
Remarks
To return the collection of items for a list or document library, use the Items property or one of the GetItems methods of the SPList class or use the Items property or GetItemsInFolder method of the SPDocumentLibrary class. To create an item, use the Add method represented in the previous table.
Use an indexer to return a single list item from the collection. For example, assuming the collection is assigned to a variable named myItems, use myItems[index]
in C#, or myItems(index)
in Visual Basic .NET, where index is either the index number of the item in the collection or the display name of a list field.
Example
The following code example uses the GetView method to return particular items from a source list in one site and then adds these items to a destination list in another site.
This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.
Requirements
Namespace: Microsoft.SharePoint
Platforms: Microsoft Windows Server 2003
Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)
Security: Code Access Security