Partager via


SPChangeQuery.Item - Propriété

Obtient ou définit une valeur Boolean qui indique si les modifications apportées aux objets SPListItem sont incluses dans la requête.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public Property Item As Boolean
    Get
    Set
'Utilisation
Dim instance As SPChangeQuery
Dim value As Boolean

value = instance.Item

instance.Item = value
public bool Item { get; set; }

Valeur de propriété

Type : System.Boolean
true pour inclure les modifications apportées aux éléments de la liste ; dans le cas contraire, false. La valeur par défaut est false.

Exemples

L'exemple suivant est une application console qui interroge le journal modification pour les modifications apportées aux éléments sur toutes les listes dans une collection de sites. Après avoir récupéré les modifications, l'application examine chaque modification et imprime la date de la modification, l'URL du site Web, le titre de la liste, le nom complet de l'élément et le type de modification.

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();
      }
   }
}

Voir aussi

Référence

SPChangeQuery classe

SPChangeQuery - Membres

Microsoft.SharePoint - Espace de noms

SPChangeItem