共用方式為


SPSite.GetChanges method (SPChangeToken)

傳回集合的變更,從變更記錄檔中的特定點開始。

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

Syntax

'宣告
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
    Type: Microsoft.SharePoint.SPChangeToken

    指定的開始日期及時間的SPChangeToken物件。語彙基元,指的是之前的目前開始變更記錄檔的時間,會擲回例外狀況SPException 。若要變更記錄檔的開頭,請傳遞a null reference (Nothing in Visual Basic)語彙基元。

傳回值

Type: Microsoft.SharePoint.SPChangeCollection
SPChange 代表的物件所做的變更集合。

備註

您可以取得要做為引數傳遞給這個方法藉由從上次變更前呼叫GetChanges方法所傳回的ChangeToken屬性中擷取的SPChangeToken物件。或者,您可以使用SPChangeToken建構函式來建立新的變更語彙基元。

如果您建構SPChangeToken物件來使用這個方法時,會傳遞SPChangeCollection.CollectionScope。建構函式的第一個引數,目前物件的SPSite.ID屬性,做為第二個引數和第三個引數的DateTime物件的值為Site 。

注意事項注意事項

根據預設,變更記錄會保留資料的 60 天。您可以藉由設定ChangeLogRetentionPeriod屬性設定的保留期限。

Examples

下列範例是示範如何取得所有變更記錄檔中的主控台應用程式。程式迴圈取得變更批次時,並中斷迴圈外時,它會擷取具有零的成員,表示它已達到記錄結尾的集合。

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 class

SPSite members

GetChanges overload

Microsoft.SharePoint namespace

ChangeToken

CurrentChangeToken

其他資源

Using the Change Log