共用方式為


SPContentDatabase.GetChanges method (SPChangeToken)

會傳回集合的內容資料庫的變更,從指定的日期開始。

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

Syntax

'宣告
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
)

參數

傳回值

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

備註

您可以取得SPChangeToken物件以做為引數傳遞給此方法來擷取一個來自先前呼叫GetChanges方法所傳回的最後一個修訂的ChangeToken屬性。或者,您可用來建立新的變更 token SPChangeToken建構函式。

注意事項注意事項

根據預設,變更記錄會保留在 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;

            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 class

SPContentDatabase members

GetChanges overload

Microsoft.SharePoint.Administration namespace

其他資源

Using the Change Log