sreenu kolusu

sreenu kolusu

  • NA
  • 38
  • 181.5k

How to Create Content Type Using Visual Studio 2010

Aug 9 2012 2:08 PM
1. Open Visual Studio 2010 , GO to File --> New --> Project or (ctrl+shift+N).

2. Select SharePoint --> 2010 under Installed Templates which on left handside.

Then Select ContentType and name the project Here i am naming it as "EmpContentType". And Click on 'OK'.

3. Now it will open SharePoint Customization Wizard, in this specify 'What local site do you want to user for debugging' here it is "http://demoshare:6969" and 'what is the trust level for this SharePoint Solution' here am choosing Farmlevel so it is Deploy as a farm solution.
Then click 'Next'.



4. Here we need to choose 'Which Base content type should this content type inherit from' i.e parent Content Type, Here am selecting 'Document'. Now Click on 'Finish'.



Note: <ContentType ID="0x010100df9cc96d389c439dba13a1b6fd2bd431"> in this 0xO101 is specify parent content type and then 'df9cc96d389c439dba13a1b6fd2bd431' is new guid for content type in between these two values '00' is added by default.

5. Now Right Click on Project --> add new item --> select Empty Element and name it as 'EMPCTFields'. This in empty element we will specify what are the fields we are  going to use and these field references are will be add in ContentType1 Elements.



6.

Here am taking following fields in EmpContentType
Field Name        Type
EmpID             Text
EmpName           Text
EmpDepartment     Choice
EmpAddress        Note
isParmenant       Boolean
DoJ               DateTime
Manager           User
Age               Integer
EmpQualification  MultiChoice
Other Available Field Types
<Field ID="{6C70171C-F142-40C7-A6C7-9628B5581180}" Name="EmpID" DisplayName="Employee ID" Required="TRUE" Sealed="TRUE" Type="Text"/>

here ID is new guid( To file menu Tools--> Creat GUID , in Create GUID window Click on New GUID next on Copy next on Exit. now paste that guid in ID attribute)

Type is what Type of column it is. here it is text means single line of text.




7. After creating fields we need to add these fields reference in ContentType1's Elements.xml file.

example , how to add reference for the above field

 Copy ID , Name and DispalyName attributes and place in <FieldRef/>
like <FieldRef ID="{6C70171C-F142-40C7-A6C7-9628B5581180}" Name="EmpID" DisplayName="Employee ID"/>



8.Now Click on Feature1 and Give some proper name and description.
Save all File and Deploy the solution(Build--> DeploySolution).

9. Now to your application where u deployed the solution and feature is activated i.e here it is http://demoshare:6969/ and create new Document library (because parent content type i s document) and name it is as "EmployeeResumes". 10. if we want to use newly created content type we need to change default content type. For this follow these types. a.Go to Document library settings click on Advanced Settings b. Select 'Yes' for Allow management of content types (by default it is 'no') and click on 'OK'.

 

 c. in library settings go to Content Types and click 'Add from existing site content types' and choose newly created content type.
 d. Now click Document content type from Content Types in library settings then Click Delete this content Type.

11. Now go to EmployeeResumes library add new document and fill all the columns.
12. After adding employeeresume and details.