cd ../blog

Creating Content Rules via Feature Activation

How to programmatically create Content Organizer routing rules via SPListItem, including the internal field names, the mysterious RoutingConditionProperties XML structure, and the feature activation pattern.

</>

The wonderful world of content routing is really limitless (well, almost).

After turning the entire system inside out, a new requirement was added: all content rules are the same across subsites, so every time a new subsite is provisioned, all the content rules need to be created. Doing this manually takes considerable time when you have many content types.

So: can we automate it?

The Routing Rules List

Content Organizer rules live in a hidden list — not accessible via “View All Content” — but it’s still an SPList. Via the SPWeb object, finding it isn’t difficult. Adding items is easy once you know the internal field names:

Internal NameDisplay NameType
RoutingEnabledActiveYes/No
RoutingAliasesAliasesSingle line of text
RoutingCustomRouterCustom RouterSingle line of text
RoutingRuleDescriptionDescriptionSingle line of text
RoutingPriorityPrioritySingle line of text
RoutingConditionPropertiesProperties used in ConditionsMultiple lines of text
RoutingAutoFolderPropProperty for Automatic Folder CreationSingle line of text
Route To External LocationRoute To External LocationYes/No
ContentTypeContent TypeRule (required)

Use these with an SPListItem to create routing rules via code. The best pattern is feature activation (scope: Web) with an activation dependency on the Content Organizer feature.

The Condition Mystery

The RoutingConditionProperties field is declared as multiline text — but it doesn’t actually store the condition operator or value. Set a condition and save the item; then edit it via the GUI and you’ll see only the column name, not the condition or value.

After extensive reflection on Microsoft.SharePoint.dll, I found that SharePoint converts the condition to an XML structure:

<Conditions>
  <Condition ColumnName="YourFieldName" condition="IsEqual" value="YourValue" />
</Conditions>

But what happens with this XML structure after creation still isn’t entirely clear to me. If you figure it out, please leave a comment!

Practical tip: Create one rule manually via the GUI, then inspect the list item’s raw field values to understand the exact structure you need to replicate.