Export (0) Print
Expand All

SPSite.GetChanges method (SPChangeToken, SPChangeToken)

Returns a collection of changes that have been logged over a specified period of time.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPChangeCollection GetChanges(
	SPChangeToken changeToken,
	SPChangeToken changeTokenEnd
)

Parameters

changeToken
Type: Microsoft.SharePoint.SPChangeToken

An SPChangeToken object that specifies a starting date and time.

changeTokenEnd
Type: Microsoft.SharePoint.SPChangeToken

An SPChangeToken object that specifies an ending date and time.

Return value

Type: Microsoft.SharePoint.SPChangeCollection
A collection of SPChange objects that represent the changes.

When you construct the SPChangeToken objects to use with this method, pass SPChangeCollection.CollectionScope.Site as the constructor’s first argument, the value of the current object’s SPSite.ID property as the second argument, and a DateTime object as the third argument.

In addition, the following rules apply.

  • If either token refers to a time before the start of the current change log, the method throws an SPException exception.

  • If the time of the second token is earlier than the time of the first token, the method returns an empty collection.

  • If the first token is a null reference (Nothing in Visual Basic), the change collection that is returned starts at the beginning of the current change log.

  • If the second token is a null reference (Nothing in Visual Basic), the change collection that is returned includes all changes after the date specified by the first change token, up to the limit for a single collection. If more changes occurred in this period, the first batch is returned.

NoteNote

By default, the change log retains data for 60 days. You can configure the retention period by setting the ChangeLogRetentionPeriod property.

The following example is a console application that queries the change log for changes that took place during a period of seven days. The application then prints information about each change to the console.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("http://localhost"))
         {
            using (SPWeb webSite = siteCollection.RootWeb)
            {
               SPChangeToken startToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.Site, 
                  siteCollection.ID,
                  new DateTime(2008, 11, 17));

               SPChangeToken endToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.Site, 
                  siteCollection.ID,
                  new DateTime(2008, 11, 23));

               long total = 0;
               SPChangeCollection changes = siteCollection.GetChanges(startToken, endToken);
               while (changes.Count > 0)
               {
                  total += changes.Count;

                  foreach (SPChange change in changes)
                  {
                     Console.WriteLine("\nDate: {0}", change.Time.ToShortDateString());
                     Console.WriteLine("Object type: {0}", change.GetType().ToString());
                     Console.WriteLine("Change type: {0}", change.ChangeType);
                  }

                  startToken = changes.LastChangeToken;
                  changes = siteCollection.GetChanges(startToken, endToken);
               }

               Console.WriteLine("\nTotal changes = {0:#,#}", total);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Show:
© 2014 Microsoft