SharePoint Online: How to acces the Change Log in a Site Collection (I)!

As in SharePoint OnPremises, in SharePoint Online you can access the Changes Log at different levels: Site Collection, Site and List / Library since we have available a number of objects and methods in the Client Side Object Model that help us to read the Changes Log such as:

In this post we will see how easily we can access the Changes Log for a SharePoint Online Site Collection using a Console Application Program:

  • In Visual Studio 2013, create a Console Application project and add references to Microsoft.SharePoint.Client, Microsoft.SharePoint.Client.Runtime, System.Configuration and Sistem.Web.
  • In Program.cs, add the following using directives:
using SPCSOM = Microsoft.SharePoint.Client;

using System.Net;

using System.Configuration;

using System.Security;

  • In the App.Config file, add the parameters (SharePoint Online credentials) required to connect to the SharePoint Online Site Collection:

<appSettings>

  <add key="SPOUser" value="SPOUser"/>

  <add key="SPOPassword" value="SPOPassword"/>

</appSettings>

  • Next add a static method to Program.cs in which you the objects and methods of CSOM that allow you to access the Change Log for a SharePoint Online Site Collection: the ChangeQuery class (allows us to see the Changes Log), ChangeCollection class (it provides a collection of changes), the GetChanges () method of the Site object and finally Change class:

static void QuerySPOSiteCChangeLog()

{

    try

    {

        string sSiteUrl = 

            "https://nuberosnet.sharepoint.com/sites/SPSaturdayCol/";

        using (SPCSOM.ClientContext spoCtx = new SPCSOM.ClientContext(sSiteUrl))

        {

            //

            //SharePoint Online Credentials

            //

            string sSPOUser =

                ConfigurationManager.AppSettings["SPOUser"];

            string sPassword =

                ConfigurationManager.AppSettings["SPOPassword"];

            SecureString ssPassword = new SecureString();

            foreach (char c in sPassword.ToCharArray())

                ssPassword.AppendChar(c);

            spoCtx.Credentials =

                new SPCSOM.SharePointOnlineCredentials(

                    sSPOUser, ssPassword);

 

            spoCtx.Load(spoCtx.Web, web => web.Title);

            spoCtx.Load(spoCtx.Web, web => web.Url);

            spoCtx.ExecuteQuery();

 

            Console.WriteLine("Accessing to the audit log for {0} - {1}", 

                spoCtx.Web.Title, spoCtx.Web.Url);

            SPCSOM.ChangeQuery cqChangeQuery = 

                new SPCSOM.ChangeQuery(true,true);

 

            SPCSOM.ChangeCollection ccChangeCollection = 

                spoCtx.Site.GetChanges(cqChangeQuery);

            spoCtx.Load(ccChangeCollection);

            spoCtx.ExecuteQuery();

 

            Console.WriteLine("# of Changes found in the first batch {0}", 

                ccChangeCollection.Count);

 

                foreach (SPCSOM.Change cChange in ccChangeCollection)

                {

                    Console.WriteLine("Change Type: {0} - Object Type: {1} - Change Time: {2}",

                        cChange.ChangeType, cChange.TypedObject, cChange.Time);

                }

        }

    }

    catch (Exception ex)

    {

        Console.WriteLine("Error: {0}", ex.Message);

    }

}

  • As a result of executing the Console Application, you will get a series of changes from the Change Log. For each change you will get information such as the change type, the affected object and the change time.

image

Other references:

SharePoint Online: Como acceder al log de cambios (I)!

Al igual que en SharePoint OnPremises, en SharePoint Online podemos acceder al Log de Cambios a distintos niveles: Colección de Sitios, Sitio y Lista / Biblioteca ya que tenemos disponibles una serie de objetos y métodos que nos facilitan la lectura del mismo como:

En este post vamos a ver como de forma sencilla podemos acceder al Log de Cambios para una Colección de Sitios de SharePoint Online en un programa de Aplicación de Consola:

  • En Visual Studio 2013, creamos un proyecto de tipo Aplicación de Consola y le añadimos referencias a Microsoft.SharePoint.Client, Microsoft.SharePoint.Client.Runtime, System.Configuration y Sistem.Web.
  • En Program.cs añadimos las siguientes directivas using:
using SPCSOM = Microsoft.SharePoint.Client;

using System.Net;

using System.Configuration;

using System.Security;

  • En el archivo App.Config añadimos los parámetros relativos a usuario y contraseña para conectarnos a la Colección de Sitios de SharePoint Online:
<appSettings>

  <add key="SPOUser" value="SPOUser"/>

  <add key="SPOPassword" value="SPOPassword"/>

</appSettings>

  • A continuación añadimos un método estático en el que hacemos uso de los objetos y métodos del CSOM que nos permiten acceder al Log de Cambios de la Colección de Sitios: la clase ChangeQuery (nos permite hacer una consulta al log de cambios), la clase ChangeCollection (nos da una colección de cambios), el método GetChanges() del objeto Site y finalmente la clase Change:
static void QuerySPOSiteCChangeLog()

{

    try

    {

        string sSiteUrl = 

            "https://nuberosnet.sharepoint.com/sites/SPSaturdayCol/";

        using (SPCSOM.ClientContext spoCtx = new SPCSOM.ClientContext(sSiteUrl))

        {

            //

            //SharePoint Online Credentials

            //

            string sSPOUser =

                ConfigurationManager.AppSettings["SPOUser"];

            string sPassword =

                ConfigurationManager.AppSettings["SPOPassword"];

            SecureString ssPassword = new SecureString();

            foreach (char c in sPassword.ToCharArray())

                ssPassword.AppendChar(c);

            spoCtx.Credentials =

                new SPCSOM.SharePointOnlineCredentials(

                    sSPOUser, ssPassword);

 

            spoCtx.Load(spoCtx.Web, web => web.Title);

            spoCtx.Load(spoCtx.Web, web => web.Url);

            spoCtx.ExecuteQuery();

 

            Console.WriteLine("Accessing to the audit log for {0} - {1}", 

                spoCtx.Web.Title, spoCtx.Web.Url);

            SPCSOM.ChangeQuery cqChangeQuery = 

                new SPCSOM.ChangeQuery(true,true);

 

            SPCSOM.ChangeCollection ccChangeCollection = 

                spoCtx.Site.GetChanges(cqChangeQuery);

            spoCtx.Load(ccChangeCollection);

            spoCtx.ExecuteQuery();

 

            Console.WriteLine("# of Changes found in the first batch {0}", 

                ccChangeCollection.Count);

 

                foreach (SPCSOM.Change cChange in ccChangeCollection)

                {

                    Console.WriteLine("Change Type: {0} - Object Type: {1} - Change Time: {2}",

                        cChange.ChangeType, cChange.TypedObject, cChange.Time);

                }

        }

    }

    catch (Exception ex)

    {

        Console.WriteLine("Error: {0}", ex.Message);

    }

}

  • La salida por pantalla que se obtiene nos da una serie de cambios del Log de Cambios identificando el tipo de cambio, el tipo de objeto afectad y la fecha del cambio.

image

Otras referencias:

[MVP CLUSTER]: Disponible la Presentación Corporativa de la Línea de Seguridad!

La seguridad tanto de los Sistemas de Información como de la información en sí misma resulta fundamental en el mundo actual como demuestra que las empresas de todo tipo se preocupen y busquen mecanismos para evitar fugas de información, proteger sus sistemas frente a ataques de terceros o simplemente asegurarse de que todos sus sistemas y todas sus aplicaciones están completamente configurados desde la perspectiva de seguridad y confidencialidad de la información que contienen. En MVP CLUSTER somos conscientes de que la Seguridad en los Sistemas de Información es un aspecto clave para cualquier organización, y en este sentido de la mano de nuestro Team Leader de Seguridad (Cristobal Espinosa, @tobalesmo) hemos preparado una oferta de soluciones y servicios de seguridad que cubre aspectos como: Gestión de Backups; Auditoría Interna; Auditoría Externa; Auditoría Web;Auditoría de Código Fuente; Aseguramiento de la Continuidad de negocio; Formación especializada en Seguridad. Para conocer los detalles de nuestros servicios y soluciones de Seguridad os recomendamos visitar nuestra presentación corporativa http://www.slideshare.net/MVPCLUSTER/mvp-cluster-presentacin-corporativa-de-la-lnea-de-seguridad o bien contactar con nosotros en las siguientes direcciones de correo: cristobal.espinosa@FiveShareIT.es, juancarlos.gonzalez@fiveshareit.es e info@fiveshareit.es