Condividi tramite


SharePoint 2010 ECM Code Sample: Content Type Based Metadata

Use this SharePoint 2010 code sample to learn how to apply metadata based on a specified content type.

Applies to: SharePoint Server 2010

Microsoft SharePoint Server 2010 includes metadata defaults based on columns, lists, and folders. However, there may be cases where you want to apply metadata based on a specified content type. For example, if you have a view where you want to order and group content types, you would want to apply metadata by content type.

In this Content Type Based Metadata code sample, some content types and a Grouping column are hard-coded. All of the content types have the Grouping column, and this column should be marked hidden so that users cannot edit it. When a new item is uploaded or edited, the Grouping column is set to the appropriate value.

When items of specified content types are uploaded, a specific column is updated. You can use the Grouping column in views to group items. There may be other cases where metadata should be applied based on the specified content type of an item.

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

Building and Running the Content Type Based Sample

Test this project on your development or test site.

Building the Sample

  1. Create a folder named Microsoft.SDK.Server.Samples, and then locate the ContentTypeBasedMetadata.zip file in the path C:\Program Files\Microsoft SDKs\SharePoint 2010\Samples, and unzip the sample code into the Samples folder.

  2. In Microsoft Visual Studio 2010, open the ContentTypeBasedMetadata.sln file that is now located 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 it is not already present, add a reference to the following assembly to the project:

    • Microsoft.SharePoint.dll
  5. On the Build menu, click Deploy Solution. After the build completes, the solution is installed on your development or test site.

Running the Sample

When items of the specified content type are uploaded, the event receiver is triggered and data in the Grouping column is refreshed.

See Also

Concepts

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

Managing Enterprise Metadata in SharePoint Server 2010 (ECM)

SharePoint 2010 ECM Code Sample: Managing Managed Metadata Dependencies

Other Resources

Enterprise Content Management Resource Center

SharePoint Developer Center

SharePoint Developer Team Blog