Answered by:
SharePoint - programmatically update elements that stays in previous versions? Is it possible?

-
I have multiple lines field with these settings:
So I have some records "history" in 'MultipleLinesField':
Is it possible to get ListItem from versions collections and update this field? I understand that I can restore some version to actual, and then change field, but I want to keep order of these records from newest to last. Is it possible in OM?
I tried but no luck. I can get it, but can not change.
SPListItem itm = web.Lists["ListWithVersions"].GetItemById(1); string fieldName = itm.Fields["MultipleLinesField"].InternalName; for (int i = 0; i < itm.Versions.Count; i++) { if (itm.Versions[i][fieldName] != null) { Message("Version: " + i + Environment.NewLine + itm.Versions[i][fieldName]); // Error Property or indexer 'Microsoft.SharePoint.SPListItemVersion.this[string]' cannot be assigned to -- it is read only itm.Versions[i][fieldName] = "asdfgh"; // Error Cannot convert type 'Microsoft.SharePoint.SPListItemVersion' to 'Microsoft.SharePoint.SPListItem' ((SPListItem)itm.Versions[i]).SystemUpdate(); } }
- Edited by Rockie_ Saturday, November 28, 2015 11:39 AM formatted code in IE
Question
Answers
-
No, the listitem.versions collection is read only and cannot be edited. The only option is to create a new list item and rebuild the history from the first version to the latest, amending the metadata on the way.
This thread shows how you can rebuild a version history from scratch. https://social.msdn.microsoft.com/Forums/office/en-US/70400ac7-bb0e-4353-ac36-990133b04447/how-to-update-the-system-generated-fields-such-as-created-created-by-modified-modified-by-and?forum=sharepointdevelopment#205f884c-0dfb-4ed7-bdb8-4f273e5742e0
Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.
- Marked as answer by Dennis GuoModerator Monday, December 7, 2015 4:36 AM
-
Hi,
As Cimares said you can edit the version history for the same item as you wish but you can try with adding different item or you can try with calculated column
And this as well.
KRISHANA KUMAR
SharePoint Architect
Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful
- Marked as answer by Dennis GuoModerator Monday, December 7, 2015 4:36 AM
All replies
-
No, the listitem.versions collection is read only and cannot be edited. The only option is to create a new list item and rebuild the history from the first version to the latest, amending the metadata on the way.
This thread shows how you can rebuild a version history from scratch. https://social.msdn.microsoft.com/Forums/office/en-US/70400ac7-bb0e-4353-ac36-990133b04447/how-to-update-the-system-generated-fields-such-as-created-created-by-modified-modified-by-and?forum=sharepointdevelopment#205f884c-0dfb-4ed7-bdb8-4f273e5742e0
Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.
- Marked as answer by Dennis GuoModerator Monday, December 7, 2015 4:36 AM
-
Hi,
As Cimares said you can edit the version history for the same item as you wish but you can try with adding different item or you can try with calculated column
And this as well.
KRISHANA KUMAR
SharePoint Architect
Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful
- Marked as answer by Dennis GuoModerator Monday, December 7, 2015 4:36 AM
-