• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Creating Content Types for SharePoint 2010 in Visual Studio 2010

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.

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

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

 

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, inQuick Launch, click Shared Documents.
  3. On the Server ribbon, in theLibrary Tools tab group, click the Library
  4. On the ribbon, in theSettings section, click Library Settings.
  5. In theGeneral Settings section, click Advanced Settings.
  6. In theContent 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 theContent Types section, click Add from existing site content types.
  9. In theSelect site content types from drop-down list, click Custom Content Types.
  10. In theAvailable Site Content Types list, click Official Documents, and then click Add. Then, click OK.
  11. On the List Information page, in theContent Types section, click Change new button order and default content type.
  12. Clear theVisible check box for the Document content type, and then click OK.
Aspired to become an SharePoint? Explore the post to discover the know-hows on SharePoint training course.

To use the new content type

  1. InQuick Launch, click Shared Documents.
  2. In the list of items, clickAdd document.
  3. Browse to a document, clickOpen 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

Content type.

  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 theField should be set to a new GUID that will be unique for this field.
  • TheField 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 on this content type.

For Indepth understanding of SharePoint click on

Summary
Review Date
Reviewed Item
Creating Content Types for SharePoint 2010 in Visual Studio 2010
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Creating Content Types for SharePoint 2010 in Visual Studio 2010"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.