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: http://msdn.microsoft.com/en-us/library/ee581299.aspx What I need is the overload SPContentType constructor: SPContentType constructor (SPContentTypeId, SPContentTypeCollection, String)

1 Answer 1


It is possible to create a content type with a set ID programmatically. Please check out http://msdn.microsoft.com/en-us/library/ff798370.aspx which contains a description of how to do so through creating SPContentTypeId-objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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