Steps to create Custom Columns and Custom Content Type using Visual Studio
The steps to be followed to create a custom content type using visual studio are as follows:
- Open up the VS 2010 with the Admin priviledge
- Create a new "Content Type Project"
- Provide the URL of the site where the content type needs to be created and validate it
- If required deploy it as a SandBox Solution or else deploy it as a Farm Solution and click on the Finish button, this will create the solution
- Choose the base content type, for e.g. "Item" and click on the Finish button
- Set the scope of the feature as "Site" or whatever is needed
- In the Solution Explorer under the name provided for the content type there will be a file as "Elements.xml", open up the file, it is good to rename the xml file e.g. XXXContentType.xml
- In this file we need to provide the following details:
- ID - this is the GUID which is autogenerated
- Name - the name of the content type
- Description - the description of the content type
- Group - the heading under which it should be displayed in the site, for e.g. "Custom Content Type"
- Inherits - this should be set to "True"
- Version - this is the version number
- Build the solution to make sure there are no errors
- Now some custom fields needs to be added to the content type before it can used, to do this right click on the solution name and click on "Add a new item"
- From the window that opens up, choose the option "Empty Element" and give it a name
- In the Solution Explorer under the name provided for the custom field there will be a file as "Elements.xml", open up the file, it is good to rename the xml file e.g. XXXCustomColumns.xml
- In this file we will create the fields that are needed, the details to be provided are as follows:
- ID - this is the GUID which can be created using the Make GUID tool in VS
- Type - the type of the field
- Name - the internal name of the field
- Display Name- the name that will be displayed to the user
- Required - whether the value for this field is required or not
- Group - specify a group name
- After the fields have been created we need to map it to the content type of whose it should be a part of, in order to do so we need to open up the Elements.xml file of the content type
- In the file inside the tag "<FieldRefs></FieldRefs>" we need to add a tag as "<FieldRef ID="{GUID}"/>", the GUID should be the same that we have specified when the fields were created, the name and the display name
- Build the solution and deploy it
- Under the "Site Collection Features" of the site make sure that the feature is activated
- In the site collection under "Site Settings - Galleries - Site Columns" the columns created should be displayed
- In the site collection under "Site Settings - Galleries - Site Content Type" the content type should be displayed under the custom content type group heading
Comments
Post a Comment