Setting content organiser settings programmatically
The content organiser is a powerful feature in SharePoint that allows users to upload files to a single central area and then use rules to route the documents to the correct place.
Creating new rules programmatically is simple but what if you want to change the actual settings of the content organiser? Things like ‘require users to use the organiser', ‘allow rules to specify another site as a target location' and so on. This is one area where the SharePoint server APIs fall over a little.
The content organiser functionality is spread liberally amongst the Microsoft.SharePoint.RecordsManagement namespace. There is an EcmDocumentRoutingWeb class and various other things, including a specialised class for handling what to do about folder handling/creation. But nothing in any of the managed classes about the core settings of content organiser.
After some hunting about and a bit of trial and error, it’s actually reasonably simple to modify the content organiser settings programmatically. The settings themselves are stored as properties on the SPWeb itself, in the Properties / AllProperties collection. However, the properties don’t exist until the feature has been set. So the way to find it out, is to modify a property, and then hunt through the properties to see what got added. So in the case of the ‘allow rules to specify another site as a target location' setting, the property itself is “_routerenablecrosssiterouting”. To set it (Powershell):
$web = Get-SPWeb http://yourweb<br />
$web.AllProperties["_routerenablecrosssiterouting"] = "true"<br />
In this case, it’s a checkbox control so a boolean value, but notice it’s the string representation of a boolean as opposed to either a bit or indeed a Powershell style $true. (If you set it to anything else, you will bork the page!)