SPList.GetChanges Method (SPChangeToken)
Returns a collection of changes starting from a particular point in the change log.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public Function GetChanges ( _
changeToken As SPChangeToken _
) As SPChangeCollection
'Usage
Dim instance As SPList
Dim changeToken As SPChangeToken
Dim returnValue As SPChangeCollection
returnValue = instance.GetChanges(changeToken)
public SPChangeCollection GetChanges(
SPChangeToken changeToken
)
Parameters
changeToken
Type: Microsoft.SharePoint.SPChangeTokenThe starting date and time. To start at the beginning of the change log, set this value to a null reference (Nothing in Visual Basic).
Return Value
Type: Microsoft.SharePoint.SPChangeCollection
The changes that have occurred in the list since the date and time specified by changeToken.
Exceptions
Exception | Condition |
---|---|
SPException | changeToken refers to a time before the start of the current change log. |
Remarks
You can get an SPChangeToken object to pass as an argument to this method by extracting one from the ChangeToken property of the last change returned by a previous call to the GetChanges method. Or, you can use the SPChangeToken constructor to create a new change token.
Note
By default, the change log retains data for 60 days. You can configure the retention period by setting the ChangeLogRetentionPeriod property.
Examples
The following example is a console application that demonstrates how to get all changes in the log. The program loops while getting changes in batches and breaks out of the loop when it retrieves a collection with zero members, signifying that it has reached the end of the list.
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://localhost"))
{
using (SPWeb webSite = siteCollection.OpenWeb())
{
// Get a list.
SPList list = webSite.Lists[0];
int total = 0;
SPChangeToken token = null;
// Get the first batch of changes.
SPChangeCollection changes = list.GetChanges(token);
// Loop until we reach the end of the log.
while (changes.Count > 0)
{
total += changes.Count;
// Go get another batch.
token = changes.LastChangeToken;
changes = list.GetChanges(token);
}
Console.WriteLine("Total of {0:#,#} changes to {1} list", total, list.Title);
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As SPSite = New SPSite("https://localhost")
Using webSite As SPWeb = siteCollection.OpenWeb()
' Get a list.
Dim list As SPList = webSite.Lists(0)
Dim total As Integer = 0
Dim token As SPChangeToken = Nothing
' Get the first batch of changes.
Dim changes As SPChangeCollection = list.GetChanges(token)
' Loop until we reach the end of the log.
While changes.Count > 0
total += changes.Count
' Go get another batch of changes starting where we left off.
token = changes.LastChangeToken
changes = list.GetChanges(token)
End While
Console.WriteLine("Total of {0:#,#} changes to {1} list", total, List.Title)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
See Also
Reference
Microsoft.SharePoint Namespace