The publishing API for MCMS 2002 has several design limitations. A workaround for one of these design limiations will be discussed in this article.
The API contains a method to create a new channel but it is missing the functionality to also create custom properties in a channel. This is even more worth due to the fact that custom properties cannot be inherited in child channels. This means that either channel traversal needs to be done or the channel property needs to be set manually using Site Manager on the channel.
The workaround discussed in this article uses the fact that custom properties for postings CAN be created using Publishing API.
So instead of creating a custom property on the channel itself it needs to be created on a posting inside this channel. To do this a new posting based on a template which contains a custom property definition for the new property needs to be created inside the channel.
This also allows searches for custom properties to the channel now: instead of using the result directly you need to follow the Channel property of the returned posting to get to the channel object. But this is only a very small coding overhead.
I have implemented a sample class which uses this approach.
It automatically creates a template in specific template gallery and adds all required custom property definitions to this template.
The class exposes two methods:
- string GetCustomChannelProperty(CmsContext, Channel, PropertyName)
- void SetCustomChannelProperty(CmsContext, Channel, PropertyName, Value)
If the custom property definition exists on the channel then the value is stored in the standard custom property collection of the channel. If not it uses the workaround discussed above.
The sample is available here.