SPList.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 SPList
Dim changeToken As SPChangeToken
Dim changeTokenEnd As SPChangeToken
Dim returnValue As SPChangeCollection
returnValue = instance.GetChanges(changeToken, _
changeTokenEnd)
public SPChangeCollection GetChanges(
SPChangeToken changeToken,
SPChangeToken changeTokenEnd
)
參數
changeToken
Type: Microsoft.SharePoint.SPChangeToken開始日期與時間。
changeTokenEnd
Type: Microsoft.SharePoint.SPChangeToken結束的日期與時間。
傳回值
Type: Microsoft.SharePoint.SPChangeCollection
變更。
Exceptions
Exception | Condition |
---|---|
SPException | changeToken或changeTokenEnd不是有效的 token。 |
備註
當您建構SPChangeToken物件,此方法搭配使用時,請傳遞SPChangeCollection.CollectionScope。List以建構函式的第一個引數,屬性的值目前物件的SPList.ID做為第二個引數,以及作為第三個引數的DateTime物件。
此外,適用下列規則:
如果任一權杖參照之前將目前的變更記錄檔的開始時間,此方法會擲回例外狀況。
如果第二個語彙基元的時間之前的時間的第一個 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;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://localhost"))
{
using (SPWeb webSite = siteCollection.OpenWeb())
{
// Get a list.
SPList list = webSite.Lists[0];
SPChangeToken startToken = new SPChangeToken(
SPChangeCollection.CollectionScope.List,
list.ID,
new DateTime(2008, 10, 12));
SPChangeToken endToken = new SPChangeToken(
SPChangeCollection.CollectionScope.List,
list.ID,
new DateTime(2008, 10, 18));
SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
int total = 0;
// Get the first batch of changes.
SPChangeCollection changes = list.GetChanges(startToken, endToken);
// Loop until we reach the end of the log.
while (changes.Count > 0)
{
total += changes.Count;
// Print info about each change to the console.
foreach (SPChange change in changes)
{
Console.WriteLine("\nDate: {0}",
timeZone.UTCToLocalTime(change.Time).ToString());
Console.WriteLine("Object type: {0}", change.GetType().ToString());
Console.WriteLine("Change: {0}", change.ChangeType.ToString());
}
// Go get another batch.
startToken = changes.LastChangeToken;
changes = list.GetChanges(startToken, endToken);
}
Console.WriteLine("\nTotal of {0} changes to {1} list", total, list.Title);
}
}
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.OpenWeb()
' Get a list.
Dim list As SPList = webSite.Lists(0)
Dim startToken As New SPChangeToken(SPChangeCollection.CollectionScope.List, _
list.ID, _
New DateTime(2008, 10, 12))
Dim endToken As New SPChangeToken(SPChangeCollection.CollectionScope.List, _
list.ID, _
New DateTime(2008, 10, 18))
Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
Dim total As Integer = 0
' Get the first batch of changes.
Dim changes As SPChangeCollection = list.GetChanges(startToken, endToken)
' Loop until we reach the end of the log.
While changes.Count > 0
total += changes.Count
' Print info about each change to the console.
For Each change As SPChange In changes
Console.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
Console.WriteLine("Object type: {0}", change.GetType().ToString())
Console.WriteLine("Change: {0}", change.ChangeType.ToString())
Next change
' Go get another batch of changes starting where we left off.
startToken = changes.LastChangeToken
changes = list.GetChanges(startToken, endToken)
End While
Console.WriteLine(vbCrLf + "Total of {0:#,#} changes to {1} list", total, list.Title)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
請參閱
參照
Microsoft.SharePoint namespace