How to: Create a new Site Column in SharePoint 2010

As we’ve seen before, site columns can be created in a variety of ways, through the web interface, the SPD10 and the VS2010.

The main difference between creating a site column through the SPD10 and the VS2010 is that, in the second case, Visual Studio creates a feature for the new site column and then deploys the XML elements file, which represents the definition for the site column, to the appropriate place within SharePoint.

1. Execute Visual Studio 2010.
2. Create a new project. Give it a name and select “Farm Level” when it asks of you to provide a level of trust for the new application.
3. Right click on the name of the project and select Add > New Item > Empty Element. Give it a name and click OK.
4. If you wanted to create a site column of type “choice” you would have to create a FIELD and provide the choice OPTIONS. In effect, you would have to create something like the following:

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Field ID=”{3CD52207-B184-4EFF-870B-6923FE595CC5}”
Type= “Choice” AllowDeletion=”FALSE” Description=”A simple site column of type choice”
FillInChoice=”FALSE”
Name=”simpleColumn”
DisplayName=”Another Site Column”
Group=”My Favourite Columns”>
<CHOICES>
<CHOICE>1</CHOICE>
<CHOICE>2</CHOICE>
<CHOICE>3</CHOICE>
<CHOICE>4</CHOICE>
<CHOICE>5</CHOICE>
</CHOICES>
<Default>4</Default>
</Field>
</Elements>

5. You could simply paste the above in your program and click on deploy. Visual Studio would then add the new column to your site collection.

Points to note

a. the only code you will have to provide is the FIELD tag. What’s before it and after it, is provided by the VS2010.
b. you will need to provide your own GUID. If you don’t know how to do that, click here.
c. the Name that you provide for the field is for programmatic use. The DisplayName is what will appear in your SharePoint interface.
d. Group defines under which group your new field/column will be listed. If you type in a group name that is not available in your SharePoint site collection, a new group by that name will be created for you.

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.