Geeks With Blogs
Fringe SharePoint Continued


I have some basic rules when it comes to checked in code to TFS. The one at the top of the list of rules is that, any developer should get the latest code from TFS, deploy and have a working web part, workflow or any other customization in SharePoint. This means that all dependencies should be deployed with the customization. If the web part uses a custom list as a data source, then a developer should not have to manually create site columns with the ‘correct’ internal and display name, list instances with ‘correct’ list name and location, and list entries (documents, images, or list items).  Nothing annoys me more than when I have to work with someone else’s code only to dig through code to see what column names and the type of data that I should create in SharePoint and then manually create the dependencies.

Provisioning Dependencies

There are two main ways to create the dependencies for your customizations. You can provision them in code by adding a Feature Receiver or you can create the XML definitions and deploy them. You can create them programmatically but I find it quite easy to create the XML definitions and find it advantages to manage them with Feature Versioning.  But it is quite cumbersome to create the XML definitions…so…

CKS to the rescue!

If you don’t know about the CKS tools for SharePoint development ( , it is an absolute must for SharePoint Developers! I first started working with them to check out the ability to create the LINQ to SharePoint classes. A fellow SharePoint MVP asked me to proof read and give him some feed back on this article ( while he was still drafting it out. And I remembered that I had tried CKS tools to build the LINQ to SharePoint classes. In fact in the article Hilton Giesenow references that you can use the CKS tools to generate the LINQ classes. I highly recommend the article as it is quite detailed and he did a fantastic job break it down.

I digress! What we are really interested in is generating columns, content types and list templates. As a developer I am usually working inside a Virtual Machine, I manually create the columns; content types, lists and other dependencies then create my customizations within Visual Studio 2010. CKS tools gives you an ability to ‘import’ the definitions into your visual studio project and then you can deploy them with your customization! How great is that! You don’t have to fumble through XML to make sure you get the right syntax for the definition, although there is ‘intelisense’ for the XML definition. It is still nice to have this auto generated for you.

Connect to your SharePoint Site

You will need to download and install the CKS extensions but you should now be able to bring up “Server Explorer” window in VS 2010 and connect to your server.


Create the site columns and content types in your SharePoint environment first:




Notice the two Site Columns are added to the content type:


Create Site Columns

Columns are the basic essentials of content types. I usually create custom Columns with internal names preceded with an underscore and CamelCase . For example:

Internal name: “_ShortDescription”
Display Name: “Short Description”

Using Visual Studio and the Server Explorer, find the site columns and “Import Field”




Every time you add a new column it will create a new file. Rename the first generated file to “Columns”, and then cut paste the newly generated xml for new columns into this first file. I prefer organizing all my columns and content types in the same way. This way my solution is not disorganized and over populated with smaller files.

Create Content Types

Content types will reference use your custom lists and automatically set an ID that inherits from a parent Content Type. Don’t worry! The CKS extensions does it all for you!

In Visual Studio using Server Explorer find the Content types and “Import Content Type”



You can organize the content types the same way as your Site columns. Creating list templates in the next step will still recognize content types even if they are in the same file.

Create List templates + List instances

Unfortunately, you cannot create list templates and instances with the CKS extensions directly, but you can now create an artifact through visual studio!

Right click on your Visual Studio Project and “Add a new Item” and select “List Definition from Content Type”



The next screen will ask you for a list definition name, and the content type you want to base it off of. It will pick up on Content Types included in your VS project. Select the one you want to use. The important check box at the end is to create a list instance. I like doing this but it is not mandatory. This means that the list will automatically be created based on the template created. If you ‘deactivate’ and ‘activate’ the feature, the list instance will ‘clear’, meaning that the items you add to the list will be erased. So be careful about how you want to use List instances.



Creating list instances are optional but really handy. If you don’t create the list instances then you simply create the list manually based on the template.


Populate list with list items by using the list instance definition.
<ListInstance ….>
        <Row><Field Name="Title">Some Title</Field></Row>
        <Row><Field Name="Title">Second Title</Field></Row>


Populate Picture or Document Libraries using Modules.


There are two main methods to creating the dependencies in a SharePoint 2010 project, I prefer the process describe in this article. Once you have your site columns and site content types, etc. you can leverage the new SharePoint 2010 Feature Versioning to upgrade and manage features. Feature Versioning in SharePoint 2010 is worth looking at and using within your development practice.

You will now have column definitions, content type definitions, list definitions and list instances with possibly populated lists within your visual studio project. Now you can deploy a web part, or workflow that depends on these items and have it deployed at once. Imagine customizations just working on deployment!!! imagine that!

Posted on Monday, February 20, 2012 10:00 PM SharePoint , Development | Back to top

Comments on this post: CKS tools to Package Columns\Content Types\Lists Templates and List Instances

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © juanlarios | Powered by: