0

This question have been asked several times but I'm still a bit confused and hope that you can make it clear for me.

I have a site in which many Content Types have been declared via CAML in a feature.

Now I need to update these content types.
What is the best way to do it?

As far as I know it's no solution to simply update the elements.xml of the single Content Types. (https://msdn.microsoft.com/en-us/library/aa543504.aspx)
But how can I achieve it to fulfill these updates to the Content Types?

3

First, you don't declare Content Types via CAML. You declare them using XML. CAML is the Query-Language used to query lists.

If you declare Content Types via XML and deploy it by a Feature, the Content Type is created/updated on site collection level. However, if you use a Content Type in a List, then the list contains a child of that Content Type, which is actually a copy. If you update the site collection Content Type only by redeploying your XML in the Feature, the changes are NOT pushed down to inheriting (and therefore also not to children) Content Types.

You have 2 Options:

  1. Opening the ContentType in the Web Interface in the site collection Settings and click ok (this will push the current state of the ContentType down to its children)
  2. Adding a Eventreceiver to the deploying Feature, in which you grab the contentType from your sitecollection Content types and call ".Update(true)" on it (where "true" means pushing changes down to children).

You can do the latter also writing a PowerShell script.
There is also a way to do this using the FeatureUpgrade mechanism. But this is quite complex and doesn't cover all scenarios for updating a ContentType

| improve this answer | |
  • yeah for sure sorry I wanted to write XML but due to current work I had CAML in mind ;) But nevertheless. Does that mean that I can update the elements.xmlof the content type and re-deploy the solution and upgrade it without having unexpected effects afterwards? And if so what role does the inherits attribute play in content type declaration, while having a look on the push down mechanism? – Husen Sep 16 '15 at 13:45
  • 1
    inherits in the contenttype declaration means, that it also uses the fields declared in ist parent Content type. eg, if your parent is a document and you don´t inherit the fields, you have to declare the fields all by yourself, otherwise you can rely that the fields of a document are available in yours too. (usually this Parameter is set to true). Yes, you can redeploy there should be no side effects, but make sure to set the paramter for "overwrite" to true. The only effect is, in all lists, where your contenttype is added to AFTER the upgrade in XML, the new declaration will be used. – Leopold Lerch Sep 16 '15 at 13:59
  • 2
    All existing contenttypes in lists will get their changes after you push the changes down to them, either by guid or by code (eventreceiver, powershell, ...) – Leopold Lerch Sep 16 '15 at 14:00
  • Thanks a lot I will try this and will give a feedback if everything worked. I was a bit confused because many articles are saying that this is not as easy as it sounds. And one first approach was showing that the push down is not working as I expected therefore this post. – Husen Sep 16 '15 at 14:12
  • try changing something before the contenttype.update. eg. removing and adding a field again. Maybe he does a update only if something changed. – Leopold Lerch Sep 17 '15 at 8:13
0

I need to say thanks to Leopold for the help!!

To whom it might concern, I implemented the push down of the site content type changes with the help of Johan Leino's article.

With this approach you are able to also push down the changes to event receivers which are attached to the site content type.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.