SPChangeQuery.Item property
取得或設定指定是否在查詢中包含SPListItem的物件變更的Boolean值。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Property Item As Boolean
Get
Set
'用途
Dim instance As SPChangeQuery
Dim value As Boolean
value = instance.Item
instance.Item = value
public bool Item { get; set; }
Property value
Type: System.Boolean
若要包含清單項目 ; 變更true否則, false。預設值為false。
Examples
下列範例是主控台應用程式來查詢變更記錄檔,讓網站集合中的所有清單中的項目所做的變更。擷取所做的變更之後, 應用程式會檢查每項變更,並列印日期的變更,網站的 URL、 清單的標題、 項目,以及變更類型的顯示名稱。
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
' Convert to local time.
Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
' total changes
Dim total As Integer = 0
' Loop until we reach the end of the log.
While True
Dim changes As SPChangeCollection = siteCollection.GetChanges(query)
total += changes.Count ' running total
For Each change As SPChangeItem In changes
' Get information we want.
Dim webUrl As String = String.Empty
Dim listTitle As String = String.Empty
Dim itemDisplayName As String = String.Empty
' Get the web site where the change was made.
Using web As SPWeb = siteCollection.AllWebs(change.WebId)
' Url of the web site
webUrl = web.Url
' Get title of the list.
Dim list As SPList = Nothing
Try
list = web.Lists(change.ListId)
listTitle = list.Title
Catch ex As SPException
listTitle = "Unknown"
itemDisplayName = "Unknown"
End Try
' Get display name of the item.
If list IsNot Nothing Then
Try ' Is it an item?
itemDisplayName = _
list.GetItemByUniqueId(change.UniqueId).DisplayName
Catch noItem As ArgumentException
Try ' Is it a folder?
itemDisplayName = _
list.Folders(change.UniqueId).DisplayName
Catch noFolder As ArgumentException ' Must have been deleted
itemDisplayName = "No longer exists"
End Try
End Try
End If
End Using
' Write to the console.
Console.WriteLine(vbCrLf + "Date: {0}", _
timeZone.UTCToLocalTime(change.Time).ToString())
Console.WriteLine("Web site: {0}", webUrl)
Console.WriteLine("List: {0}", listTitle)
Console.WriteLine("Item: {0}", itemDisplayName)
Console.WriteLine("Change: {0}", change.ChangeType)
Next change
' Break out of the 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;
// Convert to local time.
SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
// total changes
int total = 0;
// Loop until we reach the end of the log.
while (true)
{
SPChangeCollection changes = siteCollection.GetChanges(query);
total += changes.Count; // running total
foreach (SPChangeItem change in changes)
{
// Get information we want.
string webUrl = String.Empty;
string listTitle = String.Empty;
string itemDisplayName = String.Empty;
// Get the web site where the change was made.
using (SPWeb web = siteCollection.AllWebs[change.WebId])
{
// Get url of the web site.
webUrl = web.Url;
// Get title of the list.
SPList list = null;
try
{
list = web.Lists[change.ListId];
listTitle = list.Title;
}
catch (SPException)
{
listTitle = "Unknown";
itemDisplayName = "Unknown";
}
// Get display name of the item.
if (list != null)
{
try // Is it an item?
{
itemDisplayName =
list.GetItemByUniqueId(change.UniqueId).DisplayName;
}
catch (ArgumentException)
{
try // Is it a folder?
{
itemDisplayName =
list.Folders[change.UniqueId].DisplayName;
}
catch (ArgumentException) // Must have been deleted.
{
itemDisplayName = "No longer exists";
}
}
}
}
// Write to the console.
Console.WriteLine("\nDate: {0}",
timeZone.UTCToLocalTime(change.Time).ToString());
Console.WriteLine("Web site: {0}", webUrl);
Console.WriteLine("List: {0}", listTitle);
Console.WriteLine("Item: {0}", itemDisplayName);
Console.WriteLine("Change: {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();
}
}
}