Creating Content Types for SharePoint 2010 in Visual Studio 2010
  • Share this blog:


Content Types for SharePoint

This SharePoint Visual How To walks you through the following high-level steps to show the process of creating and deploying a content type to a SharePoint 2010 site:

  1. Creating a new Content Type project in Visual Studio 2010.
  2. Editing the content type details.
  3. Adding a new field to the XML markup.
  4. Including a reference to the new field from within the content type element.

You will create a content type definition named Official Documents that is based on the Document content type. Then, you will add a choice column for Review Status, and deploy and use this content type.


Aspired to become a SharePoint? Explore the post to discover the know-how on the "SharePoint Training" course.

To create a SharePoint 2010 content-type application solution in Visual Studio 2010

  1. Start Visual Studio 2010.
  2. On the File menu, click New, and then click Project.
  3. In the Installed Templates section, expand either Visual Basic or C#, expand SharePoint, and then click 2010.
  4. In the template page, click Content-Type.
  5. In theName box, type Official Documents.
  6. Leave other fields with their default values, and then clickOK.
  7. In what local site do you want to use for debugging? box, select your site.
  8. Select the Deploy as a farm solution  Then, click Next.
  9. In the Choose Content Type Settings dialog box, in the Which base content type should this content type inherit from? list, select Document.
  10. Click Finish.


To edit the content type details in the Elements.xml file

  1. InSolution Explorer, expand ContentType1 and then open xml.
  2. Edit theName attribute in the <ContentType> tag and type Official Documents.
  3. Edit theDescription attribute in the <ContentType> tag and type Official Document Content Type.
The markup should look similar to the following.
The ContentType ID is a GUID and your ID will differ.

  XML: <ContentType ID="0x01010055a134438a8544eaa18477c8f21894d0" Name="Official Documents" Group="Custom Content Types" Description="Official Document Content Type" Inherits="TRUE" Version="0">

To add a field to the Elements.xml file

  1. Above the <ContentType> tag, add the following markup. Notice that this includes a new field that will be identified with a new GUID. For this exercise, you can either use the GUID in the following code or create your own GUID.
XML <Field ID="{30C3D21A-A7C9-410E-A896-82875475F697}" Name="ReviewStatus" DisplayName="Review Status" Type ="Choice" > <CHOICES> <CHOICE>Review Required</CHOICE> <CHOICE>Review in Progress</CHOICE> <CHOICE>Review Completed</CHOICE> </CHOICES> </Field>
  1. Between the begin and end <FieldRefs> tags in the <ContentType> tag, add the following <FieldRef> tag. Ensure that the GUID matches that of the <Field> in the previous step.
XML: <FieldRef ID="{30C3D21A-A7C9-410E-A896-82875475F697}" Name="ReviewStatus" DisplayName="Review Status" />

To deploy the project

  1. InSolution Explorer, right-click the project and then click Deploy.
  2. In SharePoint, in Quick Launch, click Shared Documents.
  3. On the Server ribbon, in the Library Tools tab group, click the Library
  4. On the ribbon, in the Settings section, click Library Settings.
  5. In the General Settings section, click Advanced Settings.
  6. In the Content Types section, in the Allow Management of Content Types option, click Yes.
  7. At the bottom of the form, clickOK.
  8. On the List Information page, in the Content Types section, click Add from existing site content types.
  9. In the Select site content types from the drop-down list, click Custom Content Types.
  10. In the Available Site Content Types list, click Official Documents and then click Add. Then, click OK.
  11. On the List Information page, in the Content Types section, click Change new button order and default content type.
  12. Clear the Visible checkbox for the Document content type, and then click OK.


To use the new content type

  1. In Quick Launch, click Shared Documents.
  2. In the list of items, click Add document.
  3. Browse to a document, click Open to upload it, and then click OK.
  4. In the dialog box, note theReview Status drop-down list that is associated with the Official Document
  1. Save the document.
This Visual How To walks you through the following:
  • A content type is created by using a wizard in Visual Studio 2010.
  • The new content type has an ID that is formed by concatenating the parent content type identifier and a GUID that is generated by Visual Studio.
  • The <Field> tag is used to define a new field that will appear on a content type.
  • The ID of the field should be set to a new GUID that will be unique for this field.
  • The Field Type is set to Choice, and then the choice options are added.

The Content-Type element is then edited so that it includes a <FieldRef> tag that specifies the new Field that has been defined by reference to the ID (GUID) of that new field. This ensures the field is included in this content type.

About Author
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.

Stay Updated

Get stories of change makers and innovators from the startup ecosystem in your inbox