SharePoint 2010 ECM Code Sample: Create a Routing Rule
Use this SharePoint 2010 code sample to create a routing rule that is used by the content organizer feature to move documents to a target document library or folder.
Applies to: SharePoint Server 2010
The Routing Rule code sample demonstrates a routing rule that uses an ItemAdded event receiver to automatically create routing rules. Routing rules are used by the content organizer feature to move documents to a target document library or folder. In this code sample, when an item of the custom folder content type is created, a routing rule is created that routes items to that folder. It is useful when you need a custom folder to store items that meet specific criteria and you want to route both existing and future content to that folder.
Download the SharePoint 2010 sample code described in this topic from Code Gallery.
Prerequisites for the Routing Rule Sample
You must activate the content organizer feature, which is a site-level feature, to use this code sample. Table 1 lists fields and content types that are also required to use the code sample.
Table 1. Fields and content types required for the code sample
Field or Content Type |
Description |
---|---|
MyTextColumn Field |
A single text column. |
My EMM Column Field |
A single value-managed metadata column. |
Custom Folder Content Type |
This content type should derive from the routing folder, and should include the MyTextColumn and My EMM Column. MyTextColumn is required. |
Browse to the CreateRoutingRuleAutomaticallyEventReceiver.zip file in the C:\Program Files\Microsoft SDKs\SharePoint 2010\Samples folder, open the *.sln file in Microsoft Visual Studio 2010. In the Properties pane of Visual Studio 2010, change the Site URL value to the absolute address of your development test site. For example, http://MyDevServer/. Ensure that you include the closing forward slash.
With this code sample, when a new custom folder content type is created, a routing rule is created in the routing rules list. Document content types that have the same MyTextColumn value are routed to that folder.
Building and Running the Routing Rule Sample
This code sample requires that the site contains a content type named Contract that is derived from the Document content type.
Building the Sample
Create a folder named Microsoft.SDK.Server.Samples, and then unzip the CreateRoutingRuleAutomaticallyEventReceiver.zip file in it.
Start Visual Studio 2010, and then open the CreateRoutingRuleItemAdded.sln file that is in the folder that you created in step 1.
In the Properties window, specify the site URL value of the absolute address of your development or test site (for example, http://mysite/). Ensure that you include the closing forward slash.
If they are not already present, add references to the following assemblies to the project:
Microsoft.Office.DocumentManagement.dll
Microsoft.SharePoint.dll
Microsoft.SharePoint.Taxonomy.dll
On the Build menu, select Deploy Solution. After the build is complete, the solution is installed on your development or test site.
Running the Sample
This sample creates a content organizer rule that organizes documents of the Contract content type into a document library within the site.
See Also
Concepts
Enterprise Content Management (ECM) Code Samples for SharePoint Server 2010
Content Organizer Feature Overview for SharePoint Server 2010 Developers (ECM)
Developing with Document Management Features in SharePoint Server 2010 (ECM)