SPChangeQuery.ChangeTokenStart property
取得或設定指定的開始日期和時間透過查詢傳回的變更的語彙基元。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Property ChangeTokenStart As SPChangeToken
Get
Set
'用途
Dim instance As SPChangeQuery
Dim value As SPChangeToken
value = instance.ChangeTokenStart
instance.ChangeTokenStart = value
public SPChangeToken ChangeTokenStart { get; set; }
Property value
Type: Microsoft.SharePoint.SPChangeToken
指定的開始日期及時間的SPChangeToken物件。語彙基元,指的是之前的目前開始變更記錄檔的時間,會擲回例外狀況SPException 。若要變更記錄檔的開頭,請設定SPChangeTokenStart屬性為a null reference (Nothing in Visual Basic)的值。
備註
您可以使用SPChangeToken建構函式,建立可以用來設定這個屬性的變更語彙基元。或者,您也可以藉由從上次變更前呼叫GetChanges方法所傳回的ChangeToken屬性中擷取取得SPChangeToken物件。
Examples
下列範例會查詢 Web 站台的使用者資訊] 清單中的項目已變更的變更記錄檔的主控台應用程式。請注意應用程式取得變更批次中藉由呼叫SPWeb.GetChanges方法在迴圈中。第一次迴圈時, ChangeTokenStart屬性的值是a null reference (Nothing in Visual Basic),表示查詢應該在變更記錄檔的開頭開始。在迴圈的底部,程式碼會將ChangeTokenStart屬性設定的批次中的最後變更的變更語彙基元的值,使變更下一個批次開始的最後一個先前離開的地方。
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As SPSite = New SPSite("https://localhost")
Using webSite As SPWeb = siteCollection.RootWeb
' Construct a query.
Dim query As New SPChangeQuery(False, True)
' Set a limit on the number of changes returned on a single trip.
query.FetchLimit = 500
' object type
query.Item = True
' Get list to query.
Dim list As SPList = webSite.Lists("User Information List")
Dim total As Integer = 0
' Loop until we reach the end of the log.
While True
Dim changes As SPChangeCollection = list.GetChanges(query)
total += changes.Count
For Each change As SPChangeItem In changes
' Get the item title.
Dim itemName As String = String.Empty
Try
Dim item As SPListItem = list.GetItemByUniqueId(change.UniqueId)
itemName = item.Name
Catch ex As ArgumentException
itemName = "Item not found"
End Try
' Write to the console.
Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToString())
Console.WriteLine("Change: {0}", change.ChangeType)
Console.WriteLine("Item: {0}", itemName)
Next change
' Break out of loop if we have the last batch.
If changes.Count < query.FetchLimit Then
Exit While
End If
' Otherwise, go get another batch.
query.ChangeTokenStart = changes.LastChangeToken
End While
Console.WriteLine(vbCrLf + "Total of {0} changes", total)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
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)
{
// Construct a query.
SPChangeQuery query = new SPChangeQuery(false, true);
// Set a limit on the number of changes returned on a single trip.
query.FetchLimit = 500;
// object type
query.Item = true;
// list to query
SPList list = webSite.Lists["User Information List"];
int total = 0;
// Loop until we reach the end of the log.
while (true)
{
SPChangeCollection changes = list.GetChanges(query);
total += changes.Count;
foreach (SPChangeItem change in changes)
{
// Get the item title.
string itemName = String.Empty;
try
{
SPListItem item = list.GetItemByUniqueId(change.UniqueId);
itemName = item.Name;
}
catch (ArgumentException)
{
itemName = "Item not found";
}
// Write to the console.
Console.WriteLine("\nDate: {0}", change.Time.ToString());
Console.WriteLine("Change: {0}", change.ChangeType);
Console.WriteLine("Item: {0}", itemName);
}
// Break out of loop if we have the last batch.
if (changes.Count < query.FetchLimit)
break;
// Otherwise, go get another batch.
query.ChangeTokenStart = changes.LastChangeToken;
}
Console.WriteLine("\nTotal changes = {0:#,#}", total);
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}