SPSite.GetChanges 方法 (SPChangeToken)

Returns a collection of changes, starting from a particular point in the change log.

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Function GetChanges ( _
    changeToken As SPChangeToken _
) As SPChangeCollection
用法
Dim instance As SPSite
Dim changeToken As SPChangeToken
Dim returnValue As SPChangeCollection

returnValue = instance.GetChanges(changeToken)
public SPChangeCollection GetChanges(
    SPChangeToken changeToken
)

参数

  • changeToken
    类型:Microsoft.SharePoint.SPChangeToken

    An SPChangeToken object that specifies a starting date and time. An SPException exception is thrown if the token refers to a time before the start of the current change log. To start at the beginning of the change log, pass a 空引用(无 在 Visual Basic 中) token.

返回值

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

备注

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.

If you construct an SPChangeToken object 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.

备注

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 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 log.

using System;
using Microsoft.SharePoint;

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

            // Get the first batch of changes.
            SPChangeCollection changes= site.GetChanges(token);

            // Loop until the end of the log is reached.
            while (changes.Count > 0)
            {
               total += changes.Count;

               foreach (SPChange change in changes)
               {
                  string str = change.ChangeType.ToString();
                  Console.WriteLine(str);
               }

               changes= site.GetChanges(token);
               token = changes.LastChangeToken;
            }

            Console.WriteLine("Total changes = {0:#,#}", total);
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")

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

         ' Get the first batch of changes.
         Dim changes As SPChangeCollection = site.GetChanges(token)

        ' Loop until the end of the log is reached.
         While changes.Count > 0
            total += changes.Count

            For Each change As SPChange In changes
               Dim str As String = change.ChangeType.ToString()
               ' Process change.
               Console.WriteLine(str)
            Next change

            token = changes.LastChangeToken
            changes = site.GetChanges(token)
         End While

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

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

End Module

另请参阅

引用

SPSite 类

SPSite 成员

GetChanges 重载

Microsoft.SharePoint 命名空间

ChangeToken

CurrentChangeToken

其他资源

Using the Change Log