Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Create Content Type using Schema

Posted by Paul on October 29, 2014


In this article we can explore how to create a content type using XML Schema.

Activities Summary

Following are our activities:

1. Create Project in Visual Studio

2. Define Content Type Fields

3. Deploy Solution

Steps

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

image

Inherit from Item as parent.

image

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

image

You will get the following view.

image

Replace the content with following.

<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

<Field ID=”{00D74D75-B775-4222-967D-D26973B8C5DB}” Name=”CustomField” DisplayName=”Custom Field” Type=”Text”/>

<Field ID=”{C3CD561C-D714-42DE-8112-C830B4108CEF}” Name=”CustomChoiceField” DisplayName=”Custom Choice Field” Type=”Choice”>

<CHOICES>

<CHOICE>Choice 1</CHOICE>

<CHOICE>Choice 2</CHOICE>

<CHOICE>Choice 3</CHOICE>

</CHOICES>

</Field>

<!– Parent ContentType: Item (0x01) –>

<ContentType ID=”0x0100CB3ADB9F2D014E3F920C47C0B14D25BD” Name=”SchemaCT” Group=”Custom Content Types” Description=”My Content Type” Inherits=”TRUE” Version=”0″>

<FieldRefs>

<FieldRef ID=”{00D74D75-B775-4222-967D-D26973B8C5DB}” Name=”Custom Field” DisplayName=”Custom Field”/>

<FieldRef ID=”{C3CD561C-D714-42DE-8112-C830B4108CEF}” Name=”Custom Choice Field” DisplayName=”Custom Choice Field”/>

<FieldRef ID=”{1DAB9B48-2D1A-47b3-878C-8E84F0D211BA}” DisplayName=”$Resources:core,Status;” Name=”_Status”/>

</FieldRefs>

</ContentType>

</Elements>

Let us try to understand what each XML block do:

· The Elements section specifies the XML namespace url. We can include Field definitions here. Fields are first defined & later referenced.

· The first Field is of type Text. We need to specify GUID for each Field

· The second Field is of type Choice. The Choice values are specified in child tag

· The section Content Type specifies information on content type like Name, Description, Group, Version etc.

· The FieldRefs section is important as it actually specified the Fields used in the content type. Please note that we are referring the Fields here which we defined previously.

· Each Field Reference should include the ID, Name and Display Name of it. We can also refer existing Site Columns here by using the ID. We are using 2 custom fields & 1 existing site column here.

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

image

You can see the columns being showing up there.

image

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

References

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldtype.aspx

Summary

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s