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.
Last modified: April 20, 2011
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.
Test this project on your development or test site.
Building the Sample
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.
In Microsoft Visual Studio 2010, open the ContentTypeBasedMetadata.sln file that is now located 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 it is not already present, add a reference to the following assembly to the project:
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.