public static void AddFieldToList(SPList list, SPField field) { list.RequireNotNull("list"); field.RequireNotNull("field"); if (!list.Fields.Contains(field.Id)) { list.Fields.Add(field); list.Update(); } }
public static void AddFieldToContentType(SPContentType cType, SPField field) { cType.RequireNotNull("cType"); field.RequireNotNull("field"); var matchingLinks = from SPFieldLink fl in cType.FieldLinks where fl.DisplayName.Equals(field.Title) select fl; if (!cType.Fields.Contains(field.Id) && matchingLinks.Count() == 0) { SPFieldLink fieldLink = new SPFieldLink(field); cType.FieldLinks.Add(fieldLink); cType.Update(true); } }