Monday, May 9, 2011

In this post we will discuss how to create a Content Type using Visual studio 2010 in SharePoint 2010. Also you can check out:

- How to create event receivers using Visual Studio 2010 in SharePoint 2010?

- Retrieve all web site title and list title in current site collection in SharePoint

- Create user profile synchronization connection in SharePoint 2013

Follow the below Steps:
Step-1:
Open Visual Studio 2010 -> File -> New Project ->Select Content Type project template type -> Then give a name and Location and Solution name. See fig below

Step-2:
Then in the SharePoint Customization Wizard give the local site URL for debugging and then select deploy as farm solution and click on next. See fig below.

Step-3:
Then in this step select a parent content type from which you want to inherit the current content type. Here I have selected the Document content type. Refer figure below.

Step-4:
After step-3, when you open the solution explorer you will see the Elements.xml file where you can change the name, description of the parent content type as seen below in the figure.

Step-5:
Then you can use Field tag to add a field to the content type. For the field ID you can go to Tools->Create GUID and copy the GUID and paste the field’s ID property. Then you can field type to choice as below.

   
      India
      Srilanks
      Pakistan
   
 
If you are using the caml.net.intellisense.vsix file then you need not worry about the intelligence support for the above xml file.

Step-6:
Then refer the above field in the Field Ref attribute in the xml as follows.

     
   
The whole XML file will look like the figure below.

Then Deploy the solution and now we are ready with the content type. To use this we have to do some administration as described below.

Step-7:
Go to Share Documents document library then in the ribbon click on Library -> Library Settings->Advance Settings and select Allow management of content types? To Yes (By default No is selected).

Then scroll down to the Content Types section in the Document Library Settings Page. Then click on Add from existing content types as show in the picture below.

-->
Step-8:
Then in the Add Content Types page Select Custom Content Type in the Select site content types from: dropdown list. Select the Content type and click on Add button and click on OK button as show in the figure.

Then we can use the content type in the Shared Documents document library.

Step-9:
Then go to the Share Document document library then click on Add new item then upload a document and then in the properties page it will show the properties like the figure below.

Hope you will enjoy.


2 Comments:

  1. You have posted on my blog requesting about this post. You look like you have used my post to create your blog post? I really don't mind if you have however, a lot of people will get upset with you doing this. I really don't mind but you do need to reference me.

    thanks paul
    http://blog.sharepointsite.co.uk/2010/08/creating-lists-programtically-in-sp2010.html

    ReplyDelete
  2. Awesome!! Described very well with support of screen shots. I was able to achieve it!! Thanks, Naimish

    ReplyDelete