Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When deploying a custom page layout that uses a custom content type, I need to include the hexadecimal value of the PublishingAssociatedContentType property. This is a problem since this value will be different for each of our environments. Having a separate elements.xml file for each environment does not fit in with our deployment strategy.

Can I omit the value from the elements.xml and programmatically set it from within a feature receiver? What would that look like?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Yes I do believe you can. At least I've made mistakes before where it wasn't set properly but it was still provisioned fine, and I could fix it through the Layout's properties in the UI (directly on Production I might add.. But that's another story) :-)

You should be able to assign a string containing the same value as in your XML file :

;#MyContentTypeName;#MyContentTypeHexID;#

Note that the PublishingAssociatedContentType is Sealed, so you will need to get the field, set its Sealed flag to false, set its value, set it back to Sealed, then .Update()

Why do you have a different associated content type on each environment?

share|improve this answer
    
In each environment the content type has the same name and is based on the article page content type. I've found though that the hex value is different in each environment. Should it be the same? If that's the case, it would certainly simplify things. –  Bruce Mar 1 '12 at 16:17
    
The out of the box article page content type ID should be the same everywhere at the site level. Inside the list it gets copied into a child (variable) content type, but you can bind your layout to the (fixed) site-level ID. –  Louis Mar 1 '12 at 16:56
    
Yes, but of course I need to bind my layout to a custom content type that is only based on the Article Page content type. My custom content type already exists in each environment and has a different content type id in each environment. Do I need to remove this content type id from each environment and create it through code, so that I can control the generated ID myself? This seems like more work than it should be just to deploy a page layout that uses a custom content type. –  Bruce Mar 1 '12 at 19:10
    
A related answer is here: sharepoint.stackexchange.com/questions/14537/… but your sealed advice helped as well. Thanks! –  Bruce Mar 2 '12 at 23:43

Your Answer

 
discard

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.