SPChangeToken Constructor (SPChangeCollection.CollectionScope, Guid, DateTime)
Initializes a new instance of the SPChangeToken class with a specified change collection scope, corresponding object identifier (ID), and change time.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public Sub New ( _
scope As SPChangeCollection.CollectionScope, _
scopeId As Guid, _
changeTime As DateTime _
)
'Usage
Dim scope As SPChangeCollection.CollectionScope
Dim scopeId As Guid
Dim changeTime As DateTime
Dim instance As New SPChangeToken(scope, scopeId, _
changeTime)
public SPChangeToken(
SPChangeCollection.CollectionScope scope,
Guid scopeId,
DateTime changeTime
)
Parameters
scope
Type: Microsoft.SharePoint.SPChangeCollection.CollectionScopeThe scope of the change token, which can be a list, Web site, site collection, or content database.
scopeId
Type: System.GuidThe GUID of the scope.
changeTime
Type: System.DateTimeThe date and time of a change. Times in the change log are specified in Coordinated Universal Time (UTC) format.
Remarks
Change tokens are specific to a particular list, Web site, site collection, or content database. When you construct a change token, the values that you use in the first two parameters of the constructor should match the object that you are programming against. For example, if you intend to pass the change token to the GetChanges method of an SPList object, you must specify SPChangeCollection.CollectionScope.List as the scope and the value of the list ID property as the scopeId.
Examples
The following example is a console application that constructs two change tokens so that it can query the change log for changes to a site collection during a seven-day period.
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://localhost"))
{
// Create a query.
SPChangeQuery query = new SPChangeQuery(true, true);
// Create a change token for the start.
DateTime startTime = new DateTime(2009, 6, 1);
query.ChangeTokenStart = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
siteCollection.ID,
startTime);
// Create a change token for the end.
query.ChangeTokenEnd = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
siteCollection.ID,
startTime.AddDays(6));
// Specify the number of changes per round trip.
query.FetchLimit = 1000;
// Keep a running total.
long total = 0;
while (true)
{
SPChangeCollection changes = siteCollection.GetChanges(query);
total += changes.Count;
foreach (SPChange change in changes)
{
Console.WriteLine("\nDate: {0}", change.Time.ToShortDateString());
Console.WriteLine("Change subclass: {0}", change.GetType().ToString());
Console.WriteLine("Change type: {0}", change.ChangeType);
}
// Break out of the loop if we have the last batch.
if (changes.Count < query.FetchLimit)
break;
// Otherwise, go get another batch.
query.ChangeTokenStart = changes.LastChangeToken;
}
Console.WriteLine("\nTotal changes = {0:#,#}", total);
}
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")
' Create a query
Dim query As New SPChangeQuery(True, True)
' Create a change token for the start.
Dim startTime As New DateTime(2009, 6, 1)
query.ChangeTokenStart = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
siteCollection.ID, _
startTime)
' Create a change token for the end.
query.ChangeTokenEnd = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
siteCollection.ID, _
startTime.AddDays(6))
' Specify the number of changes per round trip.
query.FetchLimit = 1000
' Keep a running total.
Dim total As Long = 0
While True
Dim changes As SPChangeCollection = siteCollection.GetChanges(query)
total += changes.Count
For Each change As SPChange In changes
Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToShortDateString())
Console.WriteLine("Change subclass: {0}", change.GetType().ToString())
Console.WriteLine("Change type: {0}", change.ChangeType)
Next change
' Break out of loop if we have the last batch.
If changes.Count < query.FetchLimit Then
Exit While
End If
' Otherwise, go get another batch.
query.ChangeTokenStart = changes.LastChangeToken
End While
Console.WriteLine(vbCrLf + "Total changes = {0:#,#}", total)
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module