Monday, April 2, 2012

Build a Feature based Solution to Deploy Site columns in SharePoint

I have got a bunch of site columns created in development environment and want to port them to Production environment with out manually creating em again. Let see step by step: creating feature based solution for SharePoint 2010 site columns using Visual Studio 2010.

1. Lets start by creating a new Visual Studio 2010 Project.
sharepoint site column feature

2. Choose "Empty SharePoint Project" as project type, under SharePoint 2010, give it a name, Here
I've given "Crescent.Portal.SiteColumns.Feature", and don't forget to set the framework to .Net Framework 3.5 and click "Ok".
sharepoint 2010 create site column feature

3. Select the Project type, which ever applicable to you. Here I've selected farm solutions for the maximum control.

 4. Now the project will look like the below one.

5. Lets add a new to our project by right clicking and then selecting "Add >> New Item" menu
sharepoint create site column feature

6. Choose "Empty Element", name it and click Add button. This will add new element.xml to our project.
sharepoint 2010 create site column feature

7. We'll add little more meaning to the feature by just renaming it to "SiteColumnFeature"
sharepoint site columns visual studio 2010

8. To create SharePoint site column feature, we need to add the field type schema to the Elements.xml file. How do we do that? well, There are many ways, We can use Visual Studio 2010 Server explorer to get the schema XML. But I'm a big fan of SharePoint Manager!(Get it from
sharepoint site column definition

Open the SharePoint Manager, Navigate to the Source site where fields are already created
Navigate till "Fields" node, Select the desired field, click on Schema XML tab, Copy the xml node <Field type> paste it inside element.xml file in visual studio project. Highlighted is the SharePoint site column definition xml.
sharepoint site column definition xml

Repeat this for all fields.
and the Element.xml file was looking like this, once I copy-pasted all of my desired fields. Typical SharePoint site column definition:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <Field Type="Choice" DisplayName="Bpt-Departments" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" Format="RadioButtons" FillInChoice="FALSE" Group="Bpt Columns" ID="{ad2d13ee-e48e-4697-8823-8155d5fa3cfc}" SourceID="{03548e22-e4b5-4ae0-b325-12c584754e72}" StaticName="Bpt-Departments" Name="Bpt-Departments">

  <Field Type="Number" DisplayName="Bpt-InvoiceNo" Required="TRUE" EnforceUniqueValues="FALSE" Indexed="FALSE" Min="1" Max="10000" Group="Bpt Columns" ID="{b81c7da6-1317-46fa-a32b-9f446c30b6e9}" SourceID="{03548e22-e4b5-4ae0-b325-12c584754e72}" StaticName="Bpt-InvoiceNo" Name="Bpt-InvoiceNo">

10. We have our Field schema ready now. Next step: Add the element to the feature. Right click the Feature name (In our case: SiteColumnFeature) node in visual studio project, choose "View Designer" . This will launch Feature Designer, one of the brand new feature in SharePoint 2010.
sharepoint 2010 add site column feature

11. Associate the element with the feature by moving it to right.
sharepoint feature to create site column

12. With Feature Designer, We can set all additional properties to our feature like Activate on Default, Image, etc.
sharepoint 2010 site columns deployment

13. We are done creating site column feature for SharePoint 2010. Lets Build, package and deploy the project. Deploy site column feature by right clicking the project and select "Deploy".
sharepoint deploy site column feature

14. Verify the deployment by going to Site action >> Site settings >> Manage Site Features
sharepoint 2010 deploy site column

15. verify the solution "Crescent Site column Feature" is deployed and activated

16. See them under Site columns!
Build a Feature based Solution to Deploy SharePoint Site columns
See the new columns deployed!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...