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!
ANSWER
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)