1

My goal is to make a backup of the metadata on any SharePoint site whenever the document or its metadata changes. The change can be triggered by a save operation or an autosave in say the Word client and/or also on the browser.

I am achieving this by querying the SharePoint changelog and backing up the metadata.

Issue

My issue is that too many unnecessary change logs are being sent in my query and slowing down my system. I need to determine when the document or its metadata has really changed.

The document library could have major versioning, major and minor versioning or no versioning.

Question

My question is: How does SharePoint work out whether or not a file or its metadata has changed before creating a version and whether I could hook into the same logic? Is there a way to reverse engineer this?

Thus far, I have been able to create an MD5 hash out of the "Modified" & "UniqueId" metadata fields on the list item but am concerned that this may not scale to custom content types.

Details

I have setup a test using the code sample from : https://github.com/sharepoint/PnP/tree/dev/Samples/Core.ListItemChangeMonitor

Logs

Based on my tests, I have found that the Changelog produces a lot of unnecessary logs for operations, like autosave and when the user saves a document without any changes.

List Documents had a Change of type to "Add" on the item with Id 8 on 28/02/2017 2:31:52 AM

List Documents had a Change of type to "SystemUpdate" on the item with Id 8 on 28/02/2017 2:31:55 AM

List Documents had a Change of type to "Update" on the item with Id 8 on 28/02/2017 2:31:54 AM

List Documents had a Change of type to "Rename" on the item with Id 8 on 28/02/2017 2:32:05 AM

List Documents had a Change of type to "SystemUpdate" on the item with Id 8 on 28/02/2017 2:32:26 AM

List Documents had a Change of type to "Update" on the item with Id 8 on 28/02/2017 2:32:27 AM

List Documents had a Change of type to "Update" on the item with Id 8 on 28/02/2017 2:32:36 AM

List Documents had a Change of type to "SystemUpdate" on the item with Id 8 on 28/02/2017 2:32:44 AM

List Documents had a Change of type to "Update" on the item with Id 8 on 28/02/2017 2:33:11 AM

List Documents had a Change of type to "Update" on the item with Id 8 on 28/02/2017 2:36:17 AM

List Documents had a Change of type to "Update" on the item with Id 8 on 28/02/2017 2:38:02 AM

List Documents had a Change of type to "SystemUpdate" on the item with Id 8 on 28/02/2017 2:52:59 AM

List Documents had a Change of type to "Update" on the item with Id 8 on 28/02/2017 2:56:38 AM

However, SharePoint is smart enough to version the documents only on "real" changes.

(Note: The SharePoint time is off by an hour from my Changelog time, because it is not accounting for daylight savings)

Screenshot of SharePoint version history

Code

ChangeQuery cq = new ChangeQuery(true, true);
cq.Item = true;
cq.DeleteObject = true;
cq.Add = true;
cq.Update = true;

 cq.ChangeTokenStart = new ChangeToken();
                cq.ChangeTokenStart.StringValue = string.Format("1;3;{0};{1};-1", list.Id.ToString(), DateTime.Now.AddDays(-2).ToUniversalTime().Ticks.ToString());

ChangeCollection coll = list.GetChanges(cq);
_cc.Load(coll);
_cc.ExecuteQuery();

DisplayChanges(coll, cq.ChangeTokenStart);

Update

I have had some success creating an MD5 hash out of the UniqueID and Modified fields of the list item in the ChangeLog query. This tells me wether an item has truly changed.

However, the caveat is the SystemUpdate on a list will not set the Modified and ModifiedBy fields and I will lose metadata updates in those cases.

Still hoping for a better solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.