Skip to main content
2 of 3
general rewording

Cant update field value

I have the necessity to switch from using a default field to using a custom one in a number of list. I have also to "copy" the value contained in the old to-be-deleted column to the new created one. To achieve my goal I have tried a programmatic approach: add my custom field to the list and then copy the value from another, already created field. I had wrote this code:

SPField newField=list.Fields.CreateNewField("ExtendedPioplePicker", field.Title + "_new");
list.Fields.Add(newField);
foreach (SPItem item in list.Items)
{
    var fld = item.Fields.GetField(field.Title + "_new");
    fld.Type = Microsoft.SharePoint.SPFieldType.User;
    var value=item[field.InternalName];
    item[fld.InternalName]=value;
}

But then fld.InternalName throws an ArgumentException. What I need to do for fix problem and update data in field?