When to Call Update to Change SharePoint Content Type?
The SharePoint allows you to make changes or updates to content type through its Object Model. However, these updates are committed in the in-memory context of the site. Moreover, these update are not being update permanently in the site database. In order to rectify this situation, the SharePoint provides Update method that is designed to commit any changes to the content type into the content type definition which is permanently stored in the site database.
The SharePoint update makes changes to the site content by pushing down changes made to the parent content type to its children sites and content types.
The code sample below creates a link by using one of the existing columns. It adds it to the SharePoint website content type and makes update without propagation as explained above.
using System; using Microsoft.SharePoint; namespace contentTypeTest { class SharePointApp { static void Main(string[] args) { using (SPSite site = new SPSite("http://localhost")) { using (SPWeb web = site.OpenWeb()) { string contactInfo = "MyContactInfo"; string dbInfo = "MyBirthday"; SPContentType contentType = web.ContentTypes[contactInfo]; if (contentType == null) Console.WriteLine("{0} is not content type.", contactInfo); SPField field = null; try { field = web.Fields.GetField(dbInfo); } catch (ArgumentException ex) { Console.WriteLine("{0} is not a site column."); } if (null != field && null != contentType) { SPFieldLink link = new SPFieldLink(field); if (null == contentType.FieldLinks[link.Id]) { contentType.FieldLinks.Add(link); try { link.Update(false); } catch (SPException ex) { Console.WriteLine(ex.Message); } } else { Console.WriteLine("Content type {0} link to {1} exists", ctName, fldName); } } } } } } }