共用方式為


SPContentDatabase.GetChanges method (SPChangeToken, SPChangeToken)

會傳回一群有已登入一段指定時間的變更。

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

Syntax

'宣告
Public Function GetChanges ( _
    changeToken As SPChangeToken, _
    changeTokenEnd As SPChangeToken _
) As SPChangeCollection
'用途
Dim instance As SPContentDatabase
Dim changeToken As SPChangeToken
Dim changeTokenEnd As SPChangeToken
Dim returnValue As SPChangeCollection

returnValue = instance.GetChanges(changeToken, _
    changeTokenEnd)
public SPChangeCollection GetChanges(
    SPChangeToken changeToken,
    SPChangeToken changeTokenEnd
)

參數

傳回值

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

備註

以下規則套用至當做引數傳遞的變更 token。

  • 如果任一權杖參照之前將目前的變更記錄檔的開始時間,此方法會擲回SPException例外狀況。

  • 如果第二個權杖所指定的時間早於第一個 token 所指定的時間,方法會傳回空集合。

  • 如果a null reference (Nothing in Visual Basic)的第一個 token,會傳回變更集合啟動在目前的變更記錄的開頭。

  • 如果第二個權杖a null reference (Nothing in Visual Basic),會傳回變更集合會包含所有的變更後的第一個的變更 token,最多的單一集合的限制所指定的日期。如果此期間內發生更多的變更,則會傳回第一個批次。

注意事項注意事項

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

Examples

下列範例會查詢七天的期間的執行的變更的變更記錄檔的主控台應用程式。應用程式接著會列印主控台每項變更的相關資訊。

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            using (SPWeb webSite = siteCollection.RootWeb)
            {
               // We need to do this to get an Id. SPContentDatabase.ID property is obsolete.
               SPPersistedObject db = (SPPersistedObject)siteCollection.ContentDatabase;

               SPChangeToken startToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.ContentDB,
                  db.Id,
                  new DateTime(2008, 11, 17));

               SPChangeToken endToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.ContentDB,
                  db.Id,
                  new DateTime(2008, 11, 23));

               long total = 0;

               SPChangeCollection changes = 
                  siteCollection.ContentDatabase.GetChanges(startToken, endToken);
               while (changes.Count > 0)
               {
                  total += changes.Count;

                  foreach (SPChange change in changes)
                  {
                     Console.WriteLine("\nDate: {0}", change.Time.ToShortDateString());
                     Console.WriteLine("Object type: {0}", change.GetType().ToString());
                     Console.WriteLine("Change type: {0}", change.ChangeType);
                  }

                  startToken = changes.LastChangeToken;
                  changes = siteCollection.ContentDatabase.GetChanges(startToken, endToken);
               }

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

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

            ' We need to do this to get an Id. SPContentDatabase.ID property is obsolete.
            Dim db As SPPersistedObject = CType(siteCollection.ContentDatabase, SPPersistedObject)

            Dim startToken As New SPChangeToken(SPChangeCollection.CollectionScope.ContentDB, _
                                                db.Id, _
                                                New DateTime(2008, 11, 17))

            Dim endToken As New SPChangeToken(SPChangeCollection.CollectionScope.ContentDB, _
                                              db.Id, _
                                              New DateTime(2008, 11, 23))

            Dim total As Long = 0

            Dim changes As SPChangeCollection = _
               siteCollection.ContentDatabase.GetChanges(startToken, endToken)
            While changes.Count > 0
               total += changes.Count

               For Each change As SPChange In changes

                  Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToShortDateString())
                  Console.WriteLine("Object type: {0}", change.GetType().ToString())
                  Console.WriteLine("Change type: {0}", change.ChangeType)

               Next change

               startToken = changes.LastChangeToken
               changes = siteCollection.ContentDatabase.GetChanges(startToken, endToken)
            End While

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

         End Using
      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