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:
-
The ChangeQuery class.
-
…
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.
Other references: