Export (0) Print
Expand All

SharePoint 2010 ECM Code Sample: Create a Routing Rule

SharePoint 2010

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.

Last modified: April 20, 2011

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.

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.

This code sample requires that the site contains a content type named Contract that is derived from the Document content type.

Building the Sample

  1. Create a folder named Microsoft.SDK.Server.Samples, and then unzip the CreateRoutingRuleAutomaticallyEventReceiver.zip file in it.

  2. Start Visual Studio 2010, and then open the CreateRoutingRuleItemAdded.sln file that is in the folder that you created in step 1.

  3. 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.

  4. 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

  5. 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.

Show:
© 2014 Microsoft