获取或设置指定的开始日期和时间更改通过查询返回一个标记。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
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; }
属性值
类型:Microsoft.SharePoint.SPChangeToken
SPChangeToken 对象,该对象指定一个起始日期和时间。SPException如果异常标记指的是之前的当前开始更改日志的时间。若要从更改日志的开始处开始,将SPChangeTokenStart空引用(无 在 Visual Basic 中)值。
备注
SPChangeToken构造函数用于创建一个更改标记,可用于设置该属性。或者,通过提取一个从ChangeToken返回以前的GetChanges方法调用的最后一个变更的属性获取一个SPChangeToken对象。
示例
下面的示例是一个控制台应用程序的查询对 Web 站点的用户信息列表中的项进行的更改的更改日志。请注意应用程序通过在循环中调用SPWeb.GetChanges方法在批处理中获取更改。第一次执行循环时, ChangeTokenStart属性的值是空引用(无 在 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();
}
}
}