Export (0) Print
Expand All

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)

public SPChangeToken(
	SPChangeCollection.CollectionScope scope,
	Guid scopeId,
	DateTime changeTime
)

Parameters

scope
Type: Microsoft.SharePoint.SPChangeCollection.CollectionScope

The scope of the change token, which can be a list, Web site, site collection, or content database.

scopeId
Type: System.Guid

The GUID of the scope.

changeTime
Type: System.DateTime

The date and time of a change. Times in the change log are specified in Coordinated Universal Time (UTC) format.

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.

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("http://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();
      }
   }
}
Show:
© 2014 Microsoft