4 04 2011
Programmatically Update a Content Type
Here’s a straight forward one. For some reason (don’t ask) I had to update a content type in a Feature Receiver (I would have preferred to have created a new content type and inherit) by adding a new field to it.
Here’s the code, purely for my personal reference but open in case other people find it helpful.
<br>SPContentType myCT = web.ContentTypes[new SPContentTypeId("0x010100E271948D51B6564FB8D517B6347459D4")];<br><br>SPField myNewField = web.Fields.GetFieldByInternalName("AnotherSiteColumn");<br><br>SPFieldLink myNewFieldLink = new SPFieldLink(myNewField);<br><br>myCT.FieldLinks.Add(myNewFieldLink);<br><br>myCT.Update();<br>