SPContentDatabase.GetChanges 方法 (SPChangeToken)

返回的集合内容数据库更改时,从指定的日期开始。

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

语法

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

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

参数

返回值

类型:Microsoft.SharePoint.SPChangeCollection
代表所做的更改的SPChange对象的集合。

备注

您可以获得一个SPChangeToken对象,以提取一个从ChangeToken属性返回以前的GetChanges方法调用的最后一个变更传递给此方法作为参数。或者,您可以使用SPChangeToken构造函数创建一个新的更改标记。

备注

默认情况下,更改日志数据将保留 60 天。您可以通过设置ChangeLogRetentionPeriod属性配置的保留期间。

示例

下面的示例是一个控制台应用程序,它演示了如何获取日志中的所有更改。程序分批获取更改时循环并跳出循环,当它检索集合,与零的成员,以表明它已到达列表的末尾。

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;

            SPChangeCollection changes = site.ContentDatabase.GetChanges(token);
            while (changes.Count > 0)
            {
               total += changes.Count;

               foreach (SPChange change in changes)
               {
                  // Process change.
                  Console.WriteLine("Date: {0}  Type of object: {1}  Type of change: {2}", 
                     change.Time.ToShortDateString(), change.GetType().ToString(), change.ChangeType);
               }

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

            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

         Dim changes As SPChangeCollection = site.ContentDatabase.GetChanges(token)
         While changes.Count > 0
            total += changes.Count

            For Each change As SPChange In changes
               ' Process change.
                  Console.WriteLine("Date: {0}  Type of object: {1}  Type of change: {2}", _
                     change.Time.ToShortDateString(), change.GetType().ToString(), change.ChangeType)
            Next change

            token = changes.LastChangeToken
            changes = site.ContentDatabase.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

另请参阅

引用

SPContentDatabase 类

SPContentDatabase 成员

GetChanges 重载

Microsoft.SharePoint.Administration 命名空间

其他资源

Using the Change Log