Recommendations for using content types in SharePoint

We have recently encountered a serious problem in a production farm with content types. First, I would like to explain the background to this problem.

We have a good working function for setting content types in production and test farms. We developed and deployed (using wsps) this SharePoint feature in Visual Studio. We use publishing pages using page layouts and content types to help content editors quickly publish web pages. Unfortunately, some content types and site columns were manually updated / added by some people during the production process, so when I (the developer) make some changes to existing content types (using Visual Studio and activating / deactivating functions), SharePoint removes one or two a column (during function activation / deactivation) from content types; or columns that were not added best. I find it best practice to update content types using Visual Studio.

Now I want to make sure that site columns should not be removed from content types when activating / deactivating a function.

Note. Our content type activation / deactivation function does not contain any activation dependencies in feature.xml

+7
source share
3 answers

Recommended Approach

Based on all these factors, my suggestion would be:

β€’ Create two parameters: one for the original layout and one for making changes. (Or you can put them in the same function, I just want to distinguish where you are doing what.)

β€’ The original function must contain CAML for columns and content types. This ensures that identifiers are assigned before the type and remain constant.

β€’ If you want to update a site column by changing almost anything about it except your field type, do it using Feature Receiver. By doing this, you can call the Update method and pass a boolean value indicating whether you want all existing assets on the site that inherit this to be updated (something that you could not do through CAML.)

β€’ You can also add an existing site column (which you provided using the CAML function) to an existing type of content (which was provided through the CAML function). This is useful if the column has not been part of this content type before, etc.

β€’ In a scenario like the one I just mentioned in the last paragraph, you must disable and activate the CAML function (to provide new assets) before calling your function receiver. What will this mean for the site? Since all the columns of the site and the types of content in the lists on the site use the same identifier as those that were entered in the root directory of the site, removing its parent from the site collection will not change it. This may temporarily leave him an orphan (i.e., the relationship between this element and the element in the root directory of the node will not have a relationship, but it will function as it always has, since it really is a fully functioning copy of the original element) until you activate a function that puts the item back into the site collection. It’s like the parents go on vacation when you deactivate the function, and return home when you activate the function again. You have a choice when it comes to how you support CAML and Feature Receiver, since you have two scenarios: existing site collections and new ones.

β€’ You can make a policy that every time you write code in your function sink to update a site column or content type, you must also make changes to your CAML. This means that every time you activate the CAML function in the β€œnew” site collection, CAML will be relevant and accurate; there would be no need to run the updater function. (In your function sink, you need to make sure that you perform an additional check to make sure that the site column does not already belong to the content type before adding it, etc. If the changes are already set before the code executes.) This approach means that you need to perform only one function when creating a new collection of sites, but it also means that you save the changes in two places: in your Feature Receiver for making changes to existing sites and in your CAML for new sites. This is a cleaner approach, but also contains an element of redundancy that always leaves room for human error.

β€’ Another approach is to simply assume that whenever the basic CAML function is active, you will always execute Feature Receiver. This approach says that the only time you change CAML is to add a new site column or a new content type; otherwise, all changes occur in the receiver functions. This approach reduces redundancy, but also means that your Feature Receiver code can become quite large with all of your changes over time, and it can leave your CAML as very β€œobsolete” over time.

Src: http://blog.beckybertram.com/Lists/Posts/Post.aspx?List=eb3e1762%2Dbab0%2D4e96%2D8bc5%2Dd67d6e6bfd44&ID=18

+5
source

Updating content types is still one of the underdeveloped parts of Sharepoint that sometimes causes problems, especially in content deployment scenarios.

The best thing in your case would always be to avoid making any changes to the content types manually (using the user interface)

Whenever you set the content type, make sure you delete the previous one, and then install the new one. (Sometimes this is not possible because the pages are already created from it).

+1
source

My current approach to deploying content types is to use code as much as possible, not CAML. Thus, it is easy to fully control the logic of updates, including ensuring that manual changes do not lead to conflicts. I have a structure defined as attributes on an interface, which I also use for strongly typed access to the list, but there are several other ways you could do this.

The only part that is not available in the API is setting a specific identifier for the content type, so for this you need a caml file, but this is a small / simple file, it does not try to make updates and only with a link to a function that will also run the update code.

+1
source

All Articles