Activities Summary

The following are our activities:

  1. Create Project in Visual Studio
  2. Define Content Type Fields
  3. Deploy Solution

Procedure

Create a new project in Visual Studio. Choose Farm Solution. Then choose Add New Item > Content Type from the Office/SharePoint category of templates.

content type

Inherit from Item as parent.

choose content type setting

Close the designer view of the content type and use Solution Explorer to open the XML view.

elements

You will get the following view.

xmal code

Replace the content with the following.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  3. <Field ID="{00D74D75-B775-4222-967D-D26973B8C5DB}" Name="CustomField" DisplayName="Custom Field" Type="Text"/>
  4. <Field ID="{C3CD561C-D714-42DE-8112-C830B4108CEF}" Name="CustomChoiceField" DisplayName="Custom Choice Field" Type="Choice">
  5. <CHOICES>
  6. <CHOICE>Choice 1</CHOICE>
  7. <CHOICE>Choice 2</CHOICE>
  8. <CHOICE>Choice 3</CHOICE>
  9. </CHOICES>
  10. </Field>
  11. <!-- Parent ContentType: Item (0x01) -->
  12. <ContentType ID="0x0100CB3ADB9F2D014E3F920C47C0B14D25BD" Name="SchemaCT" Group="Custom Content Types" Description="My Content Type" Inherits="TRUE" Version="0">
  13. <FieldRefs>
  14. <FieldRef ID="{00D74D75-B775-4222-967D-D26973B8C5DB}" Name="Custom Field" DisplayName="Custom Field"/>
  15. <FieldRef ID="{C3CD561C-D714-42DE-8112-C830B4108CEF}" Name="Custom Choice Field" DisplayName="Custom Choice Field"/>
  16. <FieldRef ID="{1DAB9B48-2D1A-47b3-878C-8E84F0D211BA}" DisplayName="$Resources:core,Status;" Name="_Status"/>
  17. </FieldRefs>
  18. </ContentType>
  19. </Elements>
Let us try to understand what each XML block does:

Now save the changes and Deploy the project. Once the deployment succeeds, open SharePoint to view the new content type in the Site Settings > Site content types page.

schemaCT

You can see the columns being shown up there.

Deploy the project

This concludes our content type creation using XML Schema. If you wanted to create various field types, please see the field types in the references section.

References

SPFieldType enumeration.

Summary

In this article we have explored how to create a content type using XML Schema.