SPChangeToken 类

获取或设置一个布尔值,该值指示网站是否应该使用最少下载策略。

继承层次结构

System.Object
  Microsoft.SharePoint.SPChangeToken

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

语法

声明
<SerializableAttribute> _
Public NotInheritable Class SPChangeToken
用法
Dim instance As SPChangeToken
[SerializableAttribute]
public sealed class SPChangeToken

备注

SPChange对象所代表的更改日志中的每个条目。当记录更改时,它被标标识令牌,由SPChange对象的ChangeToken属性SPChangeToken对象代表。

您可以获取将用于标记为列表、 网站、 网站集或针对编程通过访问SPListSPWebSPSiteSPContentDatabase类的CurrentChangeToken属性的内容数据库记录下一处修订的更改令牌。

越来越多,要使用的更改令牌来限制对更改日志的查询范围。例如,您可以检索从更改日志中的特定位置开始通过将SPChangeToken对象作为参数传递给SPListSPWebSPSiteSPContentDatabase类的GetChanges方法的更改。您传递的更改令牌代表其中您希望查询开始日志中的顺序位置。

您可以还调用GetChanges方法使用两个更改令牌作为参数,指示查询的起始和结束点。同样,您可以通过调用GetChanges,此一个接受SPChangeQuery类的实例的另一个重载指定开始和结束点。此类具有可用于优化的查询,包括保留SPChangeToken对象、 ChangeTokenStart属性和ChangeTokenEnd属性的两个属性的属性。

GetChanges方法的所有重载都返回SPChangeCollection对象。单个集合中返回的更改的次数是出于性能原因,有限,因此应在循环中调用GetChanges ,直到您到达一个空集合,以表明您已达到日志的末尾,或者没有更多更改满足您的查询。执行此操作时,使用由第一批等获取第二个批次,直到您到达带有零更改的批次的LastChangeToken属性返回的令牌。检索网站集的记录的所有更改的以下代码说明了一般的方法。

// Get the first batch of changes.
SPChangeToken token = null;
SPChangeCollection changes = siteCollection.GetChanges(token);

while (changes.Count > 0)
{
   foreach (SPChange change in changes)
   {
      // Process each change.
   }

   // Go get another batch.
   token = changes.LastChangeToken;
   changes = siteCollection.GetChanges(token);
}
' Get the first batch of changes.
Dim token As SPChangeToken = Nothing
Dim changes As SPChangeCollection = siteCollection.GetChanges(token)

While changes.Count > 0
   Dim change As SPChange
   For Each change in changes
      ' Process the change.
   Next change

   ' Go get another batch.
   token = changes.LastChangeToken
   changes = siteCollection.GetChanges(token)
End While

示例

下面的示例是一个控制台应用程序使用SPChangeToken类可返回在过去 60 天内出现在网站的更改。

备注

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

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            using (SPWeb webSite = siteCollection.RootWeb)
            {
               // Display change times as local time.
               SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;

               // Create a change token.
               DateTime startTime = DateTime.UtcNow.AddDays(-60);
               SPChangeToken startToken = new SPChangeToken(SPChangeCollection.CollectionScope.Web,
                                                            webSite.ID,
                                                            startTime);

               // Retrieve the first batch of changes.
               SPChangeCollection changes = webSite.GetChanges(startToken);

               while (changes.Count > 0)
               {
                  foreach (SPChange change in changes)
                  {
                     // Process the change.
                     Console.WriteLine("\nDate: {0}", timeZone.UTCToLocalTime(change.Time).ToString());
                     Console.WriteLine("Change subclass: {0}", change.GetType().ToString());
                     Console.WriteLine("Type of change: {0}", change.ChangeType.ToString());
                  }

                  // Get another batch.
                  startToken = changes.LastChangeToken;
                  changes = webSite.GetChanges(startToken);
               }
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using siteCollection As SPSite = New SPSite("https://localhost")
         Using webSite As SPWeb = siteCollection.RootWeb

            ' Display change times as local time.
            Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone

            ' Create a change token.
            Dim startTime As DateTime = DateTime.UtcNow.AddDays(-60)
            Dim startToken As SPChangeToken = New SPChangeToken(SPChangeCollection.CollectionScope.Web, _
                                                                webSite.ID, _
                                                                startTime)

            ' Retrieve the first batch of changes.
            Dim changes As SPChangeCollection = webSite.GetChanges(startToken)

            While changes.Count > 0
               Dim change As SPChange
               For Each change In changes
                  ' Process the change.
                  Console.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
                  Console.WriteLine("Change subclass: {0}", change.GetType().ToString())
                  Console.WriteLine("Type of change: {0}", change.ChangeType.ToString())
               Next

               ' Get another batch.
               startToken = changes.LastChangeToken
               changes = webSite.GetChanges(startToken)
            End While

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

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

SPChangeToken 成员

Microsoft.SharePoint 命名空间

其他资源

Using the Change Log