SPList.GetChanges method (SPChangeQuery)
取得從修訂記錄為所指定的查詢篩選清單所做的變更。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Function GetChanges ( _
query As SPChangeQuery _
) As SPChangeCollection
'用途
Dim instance As SPList
Dim query As SPChangeQuery
Dim returnValue As SPChangeCollection
returnValue = instance.GetChanges(query)
public SPChangeCollection GetChanges(
SPChangeQuery query
)
參數
query
Type: Microsoft.SharePoint.SPChangeQuery查詢。
傳回值
Type: Microsoft.SharePoint.SPChangeCollection
所做的變更記錄的清單中,依指定的查詢篩選。可以傳回單一集合中的修訂數目僅限於基於效能考量。您可以藉由設定FetchLimit屬性來調整集合的大小上限。
備註
使用此方法來篩選的變更,當您感興趣只能在變更特定物件,而不是所有物件,或只在特定的物件上的選取動作。如需查詢的詳細資訊,請參閱 < SPChangeQuery類別。
![]() |
---|
根據預設,變更記錄會保留在 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];
// Construct a query.
SPChangeQuery query = new SPChangeQuery(false, // limit object types
false); // limit change types
// Specify the object type.
query.Item = true;
// Specify change types.
query.Add = true;
query.Delete = true;
query.Update = true;
SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
int total = 0;
// Loop until we reach the end of the log.
while (true)
{
SPChangeCollection changes = list.GetChanges(query);
total += changes.Count;
// Print info about each change to the console.
foreach (SPChangeItem change in changes)
{
// Get the item name.
string itemName = String.Empty;
SPListItem item = null;
try
{
item = list.GetItemByUniqueId(change.UniqueId);
itemName = item.Name;
}
catch (ArgumentException)
{
itemName = "Unknown";
}
Console.WriteLine("\nDate: {0}",
timeZone.UTCToLocalTime(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 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)
' Construct a query
Dim query As New SPChangeQuery(False, False)
' Specify the object type.
query.Item = True
' Specify change types.
query.Add = True
query.Delete = True
query.Update = True
Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
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
' Print info about each change to the console.
For Each change As SPChangeItem In changes
' Get the item name.
Dim itemName As String = String.Empty
Dim item As SPListItem = Nothing
Try
item = list.GetItemByUniqueId(change.UniqueId)
itemName = item.Name
Catch ex As ArgumentException
itemName = "Unknown"
End Try
Console.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
Console.WriteLine("Change: {0}", change.ChangeType)
Console.WriteLine("Item: {0}", itemName)
Next change
' Break out of the loop when we fetch the last batch of changes.
If changes.Count < query.FetchLimit Then
Exit While
End If
' Go get another batch of changes starting where we left off.
query.ChangeTokenStart = changes.LastChangeToken
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