SPChangeToken constructor (SPChangeCollection.CollectionScope, Guid, DateTime)
初始化指定的變更集合領域、 對應物件識別元 (ID) 和變更時間的SPChangeToken類別的新執行個體。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Sub New ( _
scope As SPChangeCollection.CollectionScope, _
scopeId As Guid, _
changeTime As DateTime _
)
'用途
Dim scope As SPChangeCollection.CollectionScope
Dim scopeId As Guid
Dim changeTime As DateTime
Dim instance As New SPChangeToken(scope, scopeId, _
changeTime)
public SPChangeToken(
SPChangeCollection.CollectionScope scope,
Guid scopeId,
DateTime changeTime
)
參數
scope
Type: Microsoft.SharePoint.SPChangeCollection.CollectionScope可以是清單、 網站、 網站集合或內容資料庫的變更語彙基元的範圍。
scopeId
Type: System.Guid領域的 GUID。
changeTime
Type: System.DateTime日期和時間的變更。變更記錄檔中的時間都是以國際標準時間 (UTC) 格式指定。
備註
變更語彙基元專屬於特殊清單、 網站、 網站集合或內容資料庫。當您建構變更語彙基元時,您在前兩個參數的建構函式中使用的值應該符合您程式設計的物件。例如,如果您想要將變更權杖傳遞至SPList物件的GetChanges方法,您必須指定SPChangeCollection.CollectionScope.List為scope和scopeId清單ID屬性的值。
Examples
下列範例是一個主控台應用程式,建構兩個變更語彙基元,以便它可以查詢變更記錄檔,讓網站集合在七天的期間內所做的變更。
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://localhost"))
{
// Create a query.
SPChangeQuery query = new SPChangeQuery(true, true);
// Create a change token for the start.
DateTime startTime = new DateTime(2009, 6, 1);
query.ChangeTokenStart = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
siteCollection.ID,
startTime);
// Create a change token for the end.
query.ChangeTokenEnd = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
siteCollection.ID,
startTime.AddDays(6));
// Specify the number of changes per round trip.
query.FetchLimit = 1000;
// Keep a running total.
long total = 0;
while (true)
{
SPChangeCollection changes = siteCollection.GetChanges(query);
total += changes.Count;
foreach (SPChange change in changes)
{
Console.WriteLine("\nDate: {0}", change.Time.ToShortDateString());
Console.WriteLine("Change subclass: {0}", change.GetType().ToString());
Console.WriteLine("Change type: {0}", change.ChangeType);
}
// Break out of the 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();
}
}
}
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As SPSite = New SPSite("https://localhost")
' Create a query
Dim query As New SPChangeQuery(True, True)
' Create a change token for the start.
Dim startTime As New DateTime(2009, 6, 1)
query.ChangeTokenStart = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
siteCollection.ID, _
startTime)
' Create a change token for the end.
query.ChangeTokenEnd = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
siteCollection.ID, _
startTime.AddDays(6))
' Specify the number of changes per round trip.
query.FetchLimit = 1000
' Keep a running total.
Dim total As Long = 0
While True
Dim changes As SPChangeCollection = siteCollection.GetChanges(query)
total += changes.Count
For Each change As SPChange In changes
Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToShortDateString())
Console.WriteLine("Change subclass: {0}", change.GetType().ToString())
Console.WriteLine("Change type: {0}", change.ChangeType)
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 changes = {0:#,#}", total)
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module