Condividi tramite


SharePoint 2010 ECM Code Sample: Managing Managed Metadata Dependencies

Use this SharePoint 2010 code sample to learn to manage dependencies for list items.

Applies to: SharePoint Server 2010

The Managing Managed Metadata Dependencies code sample in the ManagedMetadataDependencies.zip file is located in the path C:\Program Files\Microsoft SDKs\SharePoint 2010\Samples. This sample uses an event receiver on the ItemAdded event and the ItemUpdated event in the document libraries object model to manage dependencies for list items.

Download the SharePoint 2010 sample code described in this topic from Code Gallery.

Required Columns and Relationships Between Folders for the Sample

The sample demonstrates dependency management with one column for storing managed metadata fields, one column for multivalue managed metadata fields that define other items that the current item depends on, and one column for multivalue managed metadata fields that specify the items that depend on the current item. Content types require three columns, as shown in Table 1. All three columns use the same term set.

Table 1. Required columns

Column

Description

TaxonomyName

A single-value managed metadata field that represents the name of the items. This column is required.

Dependencies

A multivalue managed metadata field that defines the other items that the current item depends on. When values for this column are updated, dependencies are created on the items that are specified.

DependOnThis

A multivalue managed metadata field that specifies the items that depend on the current item.

For example, consider two items, A and B, which are folders. Table 2 shows the relationship between Folder A and Folder B, and values of each column for each folder. In this scenario, Folder A depends on Folder B; if you look at Folder B, you can see that Folder B has no dependencies but that it depends on Folder A.

Table 2. Relationships between folders

Column Name

Folder A

Folder B

Taxonomy Name

Folder A

Folder B

Dependencies

Folder B

DependsOnThis

Folder A

Building and Running the Managing Managed Metadata Dependencies Sample

Test this project on your development or test site.

Building the Sample

In Microsoft Visual Studio 2010, open the *.sln file. 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.

Running the Sample

When an item is updated, dependencies (and data in the Dependencies column) are updated. If a change has occurred, the sample finds dependencies that have been added or removed, and then it finds items that require their DependsOnThis column to be updated. If a dependency has been removed from a property, the sample removes the property from items that the current property previously depended on.

See Also

Concepts

Enterprise Content Management (ECM) Code Samples for SharePoint Server 2010

Managing Enterprise Metadata in SharePoint Server 2010 (ECM)

Other Resources

Enterprise Content Management Resource Center

SharePoint Developer Center

SharePoint Developer Team Blog