Share via


SPChangeCollection.CountLimit Field

Specifies the maximum number of changes that a single collection object can contain.

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

Syntax

Public Const CountLimit As Integer

Dim value As Integer

value = SPChangeCollection.CountLimit
public const int CountLimit

Remarks

The value of this constant is 1000. This is the maximum number of changes that can be returned by a single call to GetChanges().

For performance reasons, changes are returned in batches of limited size. The total number of changes recorded in the content database’s change log could easily number in the millions, depending on the scope of the query. Fetching all changes in a single round trip could place an unnecessarily high demand on network and server resources.

If you want all changes recorded in the log, your code should call the GetChanges method in a loop until it returns a collection with fewer than 1000 changes. You can use the SPChangeToken from the last change of the first batch to get the second batch, and so on until you get a batch with fewer than 1000 changes.

Examples

The following example is a simple console application that demonstrates how to retrieve all changes from the current change log.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using siteCollection As SPSite = New SPSite("http://localhost")

         Dim total As Long = 0
         Dim token As SPChangeToken = Nothing

         While True

            Dim changes As SPChangeCollection = siteCollection.GetChanges(token)

            total += changes.Count

            ' Break out of the loop when we fetch the last batch of changes
            If changes.Count < SPChangeCollection.CountLimit Then
               Exit While
            End If

            ' Go get another batch of changes starting where we left off
            token = changes.LastChangeToken

         End While

         Console.WriteLine("{0:#,#} changes", total)

      End Using

      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()

   End Sub
End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("http://localhost"))
         {
            long total = 0;
            SPChangeToken token = null;

            while (true)
            {
               SPChangeCollection changes = siteCollection.GetChanges(token);

               total += changes.Count;

               // Break out of loop if we have the last batch
               if (changes.Count < SPChangeCollection.CountLimit)
                  break;

               // Otherwise, go get another batch
               token = changes.LastChangeToken;
            }

            Console.WriteLine("{0:#,#} changes", total);
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

See Also

Reference

SPChangeCollection Class

SPChangeCollection Members

Microsoft.SharePoint Namespace

GetChanges()

Other Resources

Change Log and Synchronizing Applications