Ce sujet n'a pas encore été évalué - Évaluez ce sujet

SPChangeQuery, classe (Microsoft.SharePoint)

Windows SharePoint Services 3
Defines a query that is performed against the change log in Windows SharePoint Services.

Espace de noms : Microsoft.SharePoint
Assembly : Microsoft.SharePoint (dans microsoft.sharepoint.dll)
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
public sealed class SPChangeQuery

Use an SPChangeQuery object to define a query that you can pass as an argument to a GetChanges method of the SPList, SPWeb, SPSite, or SPContentDatabase class.

The properties of the SPChangeQuery class can be used to specify filters for the query. There are two types of properties: those that apply to the type of object that has been changed, and those that apply to the type of change that occurred. Use these properties in conjunction with the SPChangeQuery constructor to define a query that will return specific data from the change log.

The following example is a console application that prints out the login names of users who have been added to groups within a site collection, as well as the groups to which they have been added and the date of the change.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("http://localhost"))
         {
            using (SPWeb rootSite = siteCollection.RootWeb)
            {
               // Construct a query.
               SPChangeQuery query = new SPChangeQuery(false, false); 

               // object type 
               query.Group = true;

               // change type
               query.GroupMembershipAdd = true;

               // Get the users and groups for the site collection.
               SPUserCollection users = rootSite.AllUsers;
               SPGroupCollection groups = rootSite.Groups;

               // Convert to local time.
               SPTimeZone timeZone = rootSite.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 (SPChangeGroup change in changes)
                  {
                     // Try to get the group name.
                     string groupName = String.Empty;
                     try
                     {
                        SPGroup group = groups.GetByID(change.Id);
                        groupName = group.Name;
                     }
                     catch (SPException)
                     {
                        groupName = "Unknown";
                     }

                     // Try to get the user name.
                     string loginName = String.Empty;
                     try
                     {
                        SPUser user = users.GetByID(change.UserId);
                        loginName = user.LoginName;
                     }
                     catch (SPException)
                     {
                        loginName = "Unknown";
                     }

                     // Write to the console.
                     Console.WriteLine("\nDate: {0}", 
                          timeZone.UTCToLocalTime(change.Time).ToString());
                     Console.WriteLine("{0} was added to the {1} group.", 
                          loginName, groupName);
                  }

                  // Break out of loop if we have the last batch.
                  if (changes.Count < SPChangeCollection.CountLimit)
                     break;

                  // Otherwise, go get another batch.
                  query.ChangeTokenStart = changes.LastChangeToken;
               }

               Console.WriteLine("\nTotal changes = {0:#,#}", total);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
System.Object
  Microsoft.SharePoint.SPChangeQuery
Les membres statiques publics de ce type (Shared en Visual Basic) sont sécurisés au niveau des threads. Il n'est pas garanti que les membres d'instance soient sécurisés au niveau des threads.
Cela vous a-t-il été utile ?
(1500 caractères restants)
Microsoft réalise une enquête en ligne pour recueillir votre opinion sur le site Web de MSDN. Si vous choisissez d’y participer, cette enquête en ligne vous sera présentée lorsque vous quitterez le site Web de MSDN.

Si vous souhaitez y participer,
© 2013 Microsoft. Tous droits réservés.