Partager via


SPChangeQuery.User - Propriété

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

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

Syntaxe

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

value = instance.User

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

Valeur de propriété

Type : System.Boolean
true pour inclure les modifications apportées par les utilisateurs. dans le cas contraire, false. La valeur par défaut est false.

Exemples

L'exemple suivant est une application console qui interroge pour toutes les modifications apportées aux utilisateurs et imprime des informations sur chaque modification apportée à la console.

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)
            {
               SPChangeQuery query = new SPChangeQuery(false, true);

               // object type
               query.User = true;

               // Get the user collection. 
               SPUserCollection users = webSite.AllUsers;

               int total = 0;

               // Loop until we reach the end of the log.
               while (true)
               {
                  SPChangeCollection changes = siteCollection.ContentDatabase.GetChanges(query);

                  total += changes.Count;

                  // Print info about each change to the console.
                  foreach (SPChange change in changes)
                  {
                     // Get the user's login name.
                     string loginName = String.Empty;
                     SPChangeUser changedUser = (SPChangeUser)change;
                     try
                     {
                        SPUser user = users.GetByID(changedUser.Id);
                        loginName = user.LoginName;
                     }
                     catch (SPException)
                     { 
                        loginName = "Unknown";
                     }
                     
                     Console.WriteLine("\nDate: {0}", change.Time.ToString());
                     Console.WriteLine("Change: {0} user", change.ChangeType.ToString());
                     Console.WriteLine("Login name: {0}", loginName);
                  }

                  // 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", 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")
         Using webSite As SPWeb = siteCollection.RootWeb

            Dim query As New SPChangeQuery(False, True)

            ' object type
            query.User = True

            ' Get the users.
            Dim users As SPUserCollection = webSite.AllUsers

            Dim total As Integer = 0

            ' Loop until we reach the end of the log.
            While True
               Dim changes As SPChangeCollection = siteCollection.ContentDatabase.GetChanges(query)

               total += changes.Count

               ' Print info about each change to the console.
               For Each change As SPChange In changes

                  ' Get the user's login name.
                  Dim loginName As String = String.Empty
                  Dim changedUser As SPChangeUser = CType(change, SPChangeUser)
                  Try
                     Dim user As SPUser = users.GetByID(changedUser.Id)
                     loginName = user.LoginName
                  Catch ex As SPException
                     loginName = "Unknown"
                  End Try

                  Console.WriteLine(ControlChars.Lf + "Date: {0}", change.Time.ToString())
                  Console.WriteLine("Change: {0} user", change.ChangeType.ToString())
                  Console.WriteLine("Login name: {0}", loginName)
               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(ControlChars.Lf + "Total of {0} changes", total)

         End Using
      End Using

      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()

   End Sub
End Module

Voir aussi

Référence

SPChangeQuery classe

SPChangeQuery - Membres

Microsoft.SharePoint - Espace de noms

SPChangeUser