Kirk Liemohn is a Principal Software Engineer at ThreeWill. He has over 20 years of software development experience with most of that time spent in software consulting.
It must be possible
I recently found myself in a dilemma where I needed to update the Created, Created By, Modified, and Modified By fields for SharePoint list and library items in SharePoint Online. I had read in the past that some of these couldn’t be changed via CSOM, but I had seen migration tools do this when migrating to SharePoint Online, so I knew this must be possible.
Either my Google/Bing Foo was not good that day or there were just too many people out there saying it wasn’t possible, so I decided to figure it out for myself. It took a little trial and error, so I decided I should write it up in a blog post.
How to approach
The short answer is to look at the source further. The main tricks I needed to deal with were:
- When specifying the Created By (Author) or Modified By (Editor) user, I could not use the FieldUserValue object. Instead, I had to hand-craft it by concatenating the hidden user information list item ID and the fully qualified login name (e.g., “22;#i:0#.f|membership|[email protected]”).
- For some reason, you can set the Created By user (Author) just fine with list items. However, if you want to set the Created By user on library items, you need to also set the Modified By user or the change won’t stick.
- If you want to do this covertly, there are two extra steps to consider:
- To prevent creating a new version in version history, you may need to turn off version history before making the update and turn it back on afterward.
- To prevent updating the modified date, you need to set the modified date to the current modified date value. Otherwise, it will get updated to the current date.