SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First let me describe my situation:

Now I'm using object model to add two content types (inheriting Pages content type) using the FeatureActivating methode in the Feature Receiver. in the same feature, I add a module which deploy two page layouts, using respectively the two newly added content types.

I firstly created the content type using object model, then in the Elements.xml for page layouts I copied the ctype Id in the url for the AssociatedContentType. This was successful. However, when I upgrade the solution to a new site, this won't work any more because the newly added content types Id are no longer the same as the old site.

I know it would be possible using Feature based XAML: I can directly set the Guid of content types here. However I would like to know if there's a way I could do it keeping the object model. Say can I set the Id when creating the content types using the object model so I could know the content type Id for sure when deploying the page layouts. Or is it possible to set dynamically the AssociatedContentType in Elements.xml?

Thank you in advance!


According to Jan the direct answer is actually here: What I need is the overload SPContentType constructor: SPContentType constructor (SPContentTypeId, SPContentTypeCollection, String)

share|improve this question
up vote 0 down vote accepted

It is possible to create a content type with a set ID programmatically. Please check out which contains a description of how to do so through creating SPContentTypeId-objects.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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