SPListItemVersionCollection class
Represents a collection of SPListItemVersion objects.
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.SPListItemVersionCollection
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
Public NotInheritable Class SPListItemVersionCollection _
Inherits SPBaseCollection
'Usage
Dim instance As SPListItemVersionCollection
public sealed class SPListItemVersionCollection : SPBaseCollection
Remarks
Use the Versions property of the SPListItem class to return the collection of versions for a list item.
Use an indexer to return a single version from the collection. For example, if the collection is assigned to a variable named collListItemVersions, use collListItemVersions[index] in C#, or collListItemVersions(index) in Visual Basic, where index is the index number of the version in the collection. The lower the value of index, the more recent the version.
Examples
The following code example iterates through the items in a list and restores the previous version of the items if a field in the current version equals a specified value.
Dim list As SPList = New SPSite("http://MySiteCollection").AllWebs("MyWebSite").GetList("http://MySiteCollection/MyWebSite/Lists/MyList")
Dim listItems As SPListItemCollection = list.Items
Dim item As SPListItem
For Each item In listItems
If CStr(item("Title")) = "MyValue" Then
Dim versions As SPListItemVersionCollection = item.Versions
If versions.Count > 1 Then
versions.Restore(1)
End If
End If
Next item
SPList oList = new SPSite("http://MySiteCollection").AllWebs["MyWebSite"].GetList("http://MySiteCollection/MyWebSite/Lists/MyList");
SPListItemCollection collListItems = oList.Items;
foreach (SPListItem oListItem in collListItems)
{
if ((string)oListItem["Title"] == "MyValue")
{
SPListItemVersionCollection collListItemVersions =
oItem.Versions;
if (collListItemVersions.Count > 1)
{
collListItemVersions.Restore(1);
}
}
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.