Content type does not contain a column, or field. It only contains a reference to a site column or field. Therefore you should create a site column before you can add it to the content type definition.
The field reference in content type are managed through SPFieldLink object.
Add field reference from Content Type:
public static void AddFieldRefToContentType(SPContentType contentType, SPField field) { //Check if the Field reference does not exists already if (!contentType.Fields.ContainsField(field.Title)) { contentType.FieldLinks.Add(new SPFieldLink(field)); contentType.Update(); } else { //Do Nothing } }
Delete field reference from Content Type:
public static void DeleteFieldRefFromContentType(SPContentType contentType, SPField field) { //Check if the Field reference exists if (contentType.Fields.ContainsField(field.Title)) { contentType.FieldLinks.Delete(field.Title); contentType.Update(); } else { //Do Nothing } }
Check MSDN information for more details on Field and Field References.
Leave a Reply