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 Name | Display Name | Type |
|---|---|---|
RoutingEnabled | Active | Yes/No |
RoutingAliases | Aliases | Single line of text |
RoutingCustomRouter | Custom Router | Single line of text |
RoutingRuleDescription | Description | Single line of text |
RoutingPriority | Priority | Single line of text |
RoutingConditionProperties | Properties used in Conditions | Multiple lines of text |
RoutingAutoFolderProp | Property for Automatic Folder Creation | Single line of text |
Route To External Location | Route To External Location | Yes/No |
ContentType | Content Type | Rule (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.