I have sharepoint list 'Events' with field Location.
I am trying to add from web existing field with same internal name from other package.
var fields = contentType.ParentWeb.Fields;
SPField fieldToAdd = null;
foreach (SPField field in fields)
{
if (field.Id == fieldId)
{
fieldToAdd = field;
break;
}
}
contentType.FieldLinks.Add(new SPFieldLink(fieldToAdd));
And i got exception:
A duplicate field name "Location" was found.
When i am adding this fields in sharepoint UI it will be changed to Location0 and will be successfully added!
How to do actually the same in code? I want to add them both and its acceptable to change one internal name to Location0.