How to update all elements child of a Content Type programmatically
-
09-12-2019 - |
Question
when (by web interface) user access to a content type (in site settings -> content types) and adds or remove a column there is a flag near the end that says something like:
"Update all content types inheriting from this type?" YES / NO
If yes, every list in the site that uses the CT updates with the new column.
I'm in a project in which content types are deployed in a WSP. Whenever I update one of them the behavior is like "Update all content types inheriting from this type?" NO..
How could I change this setting setting it to YES? Is there a flag in the xml?
Thank you!
I see that when I retract from VS everything goes fine... So I tried to investigate WHAT VS does...
I tried this script:
Disable-SPFeature -Identity "f5768894-9568-49bb-8c11-354e2d42c6bd" -url URL
Uninstall-spfeature -identity "f5768894-9568-49bb-8c11-354e2d42c6bd" -force
Uninstall-SPSolution -identity saviogd.wsp -allwebapplications -force
Remove-SPSolution -identity saviogd.wsp -force
I'm gone to the SP folder and look for "something remains on it", but:
- Feature Folder is no more installed
- Layouts Folder is no more installed
So I may suppose I've done the same VS Operations... Now running an IISRESET, going to the Content Types section I found ALL Content TYpe installed and all columns remove... When I deploy again the CT has all the old data.
Checking the situazion when VS retract I see that there is no more my Content Types...
How can I get the same VS Result?
Solution
The two "official" ways to update a deployed content type are:
- AddContentTypeField which has a PushDown attribute
- Code in CustomUpgradeAction where the SPContentType.Update method takes an upgradeChildren parameter