This is the code I wrote to reorder fields in a custom content type:
//get the content type
SPContentType listContentType = myList.ContentTypes[MyContentTypeName];
//get the field name to put first
string firstFieldName = myList.Fields[FirstFieldDisplayName].InternalName;
//get all field names in the content type
List<string> fieldNames = listContentType.FieldLinks
.Cast<SPFieldLink>()
.Select(a => a.Name).ToList<string>();
//reorder field names
if (fieldNames.Remove(firstFieldName))
{
fieldNames.Insert(0, firstFieldName);
listContentType.FieldLinks.Reorder(fieldNames.ToArray<string>());
listContentType.Update();
}
I stepped through this code using a debugger and I see that the fieldNames list is used correctly - the correct field is removed and then inserted to the start of the list and the Reorder() is executed. Yet the new and edit form shows the fields in the original order. Please help.