none
SharePoint - programmatically update elements that stays in previous versions? Is it possible?

    Question

  • 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
    Saturday, November 28, 2015 11:33 AM

Answers

All replies