Delen via


How to update Content Types through the Object Model?

When we add a field to the site content type SharePoint doesn't push-down those changes to the document library and the list level. The below code sample is for push-down all the changes to document libarary and the list level.The sample code from WSS 3.0 SDK doesn't seem to be working :) 

 

SPField field = spWeb.Fields[“YourNewField”]; //you can pick one from the site column collection for create a new one.

SPFieldLink fieldLink = new SPFieldLink(field);

SPContentType contentType = spWeb.ContentTypes[“Site Level Content Type”];

contentType.FieldLinks.Add(fieldLink);

contentType.Update(true);

Comments

  • Anonymous
    May 11, 2010
    This is ok approach as long as you are not dealing with Lookup fields. For them you'll have to be careful what you are going to put in definition and to fix them later on the list level.