Skip to content

Instantly share code, notes, and snippets.

@sksnips
Created December 31, 2015 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sksnips/0de89669aa5a4415a484 to your computer and use it in GitHub Desktop.
Save sksnips/0de89669aa5a4415a484 to your computer and use it in GitHub Desktop.
Retrieve all the changes (add, update & delete) occurred on the list item using CSOM
//CSOM Assembly version - 16.1.4727.1200
//using Microsoft.SharePoint.Client;
//using System.Net
//GetItemChanges(credentials, weburl, listtitle, itemid);
//This method returns all the changes (add, update & delete) happened to the list item
private static void GetItemChanges(ICredentials credentials, string weburl, string listTitle, int itemid)
{
using (ClientContext ctx = new ClientContext(weburl))
{
ctx.Credentials = credentials;
Web oweb = ctx.Web;
ListCollection lists = oweb.Lists;
List targetList = lists.GetByTitle(listTitle);
ListItem targetItem = targetList.GetItemById(itemid);
//ChangeQuery helps the method gets the changes by setting appropriate property as true
ChangeQuery cq = new ChangeQuery();
cq.Item = true;
cq.Add = true;
cq.Update = true;
cq.DeleteObject = true;
//SP.ListItem.GetChanges(ChangeQuery) - Method available from CSOM Assembly version - 16.1.4727.1200
ChangeCollection cc = targetItem.GetChanges(cq);
ctx.Load(cc);
ctx.ExecuteQuery();
Console.WriteLine(cc.Count.ToString());
}
Console.WriteLine("Press any key to exit...");
Console.Read();
}
@KANNIBALAMK
Copy link

How to get the deleted filename?
I'm getting notification through Webhook whenever the file is added/modifed in Sharepoint. This is working fine.
But whenever the file is deleted, it's getting failed since the file itself not present when it is deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment