共用方式為


SPSite.GetChanges method (SPChangeToken, SPChangeToken)

傳回集合的一段指定時間登入的變更。

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

Syntax

'宣告
Public Function GetChanges ( _
    changeToken As SPChangeToken, _
    changeTokenEnd As SPChangeToken _
) As SPChangeCollection
'用途
Dim instance As SPSite
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 代表的物件所做的變更集合。

備註

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

此外,套用下列規則。

  • 如果其中一個語彙基元會參考到目前的變更記錄檔開頭之前的時間點,這個方法會擲回SPException例外狀況。

  • 如果第二個語彙基元的時間早於第一個語彙基元的時間,方法會傳回空集合。

  • 如果第一個語彙基元是a null reference (Nothing in Visual Basic),變更集合會傳回從目前的變更記錄檔的開頭開始。

  • 如果第二個語彙基元是a null reference (Nothing in Visual Basic),則會傳回變更集合會包含所有變更之後第一個變更語彙基元,單一集合的限制所指定的日期。如果更多的變更發生在這段期間,會傳回第一批次。

注意事項注意事項

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

Examples

下列範例是主控台應用程式,查詢在七天的期間內發生的變更的變更記錄檔。應用程式接著會列印到主控台的每個變更的相關資訊。

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)
            {
               SPChangeToken startToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.Site, 
                  siteCollection.ID,
                  new DateTime(2008, 11, 17));

               SPChangeToken endToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.Site, 
                  siteCollection.ID,
                  new DateTime(2008, 11, 23));

               long total = 0;
               SPChangeCollection changes = siteCollection.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.GetChanges(startToken, endToken);
               }

               Console.WriteLine("\nTotal changes = {0:#,#}", total);
            }
         }
         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

            Dim startToken As New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
                                                siteCollection.ID, _
                                                New DateTime(2008, 11, 17))

            Dim endToken As New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
                                              siteCollection.ID, _
                                              New DateTime(2008, 11, 23))

            Dim total As Long = 0
            Dim changes As SPChangeCollection = siteCollection.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.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

請參閱

參照

SPSite class

SPSite members

GetChanges overload

Microsoft.SharePoint namespace

SPChangeToken

其他資源

Using the Change Log