Skip to main content

Creating your own Content Type with Visual Studio 2010

Creating your own Content Type with Visual Studio 2010
We are going to see how to deploy our own Content Type for Sharepoint 2010. This approach is quite straight forward to be honest. We could build something similar programmatically but for now let’s go to concentrate how to develop a flexible solution.
I am going to develop a Content Type called DMSLegal, it will be based in a legal document management system, so considering that it should inherit the document fields plus client, matter, client description and matter description. To simplify the operation, all of them should be text columns.

image

Let’s go to start. First of all create an Empty Project, so go to Visual Studio 2010->New Project->Sharepoint->2010-> Empty Project and in the name of the folder type netsourcecodeDMSLegal.

image

Click on OK. Now select Deploy as Farm Solution and click Finish.

image

Go to your project Right Click-> Add->New Item->Content Type and in the name box type DMSLegal, click Add.

image

The next step will be selecting the Content Type where we want to inherit the fields. We don’t need to, we could just select Item(the most basic one) , but it will be faster so select Document, so we can avoid creating fields, at the end of the day a legal document it is a document with a client/matter tag. So select Document and click finish.

image

Let’s go to rename the Feature, so we can have something more comprehensive. Rename to DMSLegalCTFeature. After that go to your project and right click->Add-> New Item->Empty Element and call it DMSLegalFields and click on Add.

image

We have to define our fields in Elements.xml of the DMSLegalFields. The GUIDs can be crated with the Create GUID tool from Visual Studio 2010. Just go to Tools->Create GUID. This is how the Element.xml should look like.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field ID="{00F49879-0ECB-4736-A400-256747E1BB09}" Type="Text" Name="client" DisplayName="Client" Required="TRUE" Sealed="TRUE"/>
  <Field ID="{4E7EE8BB-262D-46EA-AAAE-F343005627DF}" Type="Text" Name="clientdescription" DisplayName="Client Description" Required="TRUE" Sealed="TRUE"/>
  <Field ID="{089A1A43-EB01-4EFF-81EE-20F46916B79F}" Type="Text" Name="matter" DisplayName="Matter" Required="TRUE" Sealed="TRUE"/>
  <Field ID="{E2B310DE-22AA-4EC0-8600-2200E5861A66}" Type="Text" Name="matterdescription" DisplayName="Matter Description" Required="TRUE" Sealed="TRUE"/>
</Elements>
Now with to associate the FieldRefs with our new fields, to do that go to the Elements.xml file under DMSLegal and add the fields. Your new Elements.xml should be this one. Notice that the IDs have to match with the GUIDs you created. Have a look to the property and add more if you want… I leave the default values to make it easy.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Document (0x0101) -->
  <ContentType ID="0x010100981bf304cdb44d1d9c0d7d794f8410b6"
               Name="netsourcecodeDMSLegal - DMSLegal"
               Group="Custom Content Types"
               Description="DMS Legal Content Types"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{00F49879-0ECB-4736-A400-256747E1BB09}" Name="client" Required="TRUE" Hidden="FALSE" ReadOnly="FALSE"/>
      <FieldRef ID="{4E7EE8BB-262D-46EA-AAAE-F343005627DF}" Name="clientdescription" Required="TRUE" Hidden="FALSE" ReadOnly="FALSE"/>
      <FieldRef ID="{089A1A43-EB01-4EFF-81EE-20F46916B79F}" Name="matter" Required="TRUE" Hidden="FALSE" ReadOnly="FALSE"/>
      <FieldRef ID="{E2B310DE-22AA-4EC0-8600-2200E5861A66}" Name="matterdescription" Required="TRUE" Hidden="FALSE" ReadOnly="FALSE"/>
    </FieldRefs>
  </ContentType>
</Elements>
Now go to your DMSLegalCTFeature , double click and change the title to netsourcecodeDMSLegal Feature. Have a look to the structure of the project to see if it matches with yours.

image

F5 and go to Site actions->Site Settings->Galleries->Site Content Types and you should have this screen:

image


Comments

Popular posts from this blog

Sharepoint Interview questions

What is Microsoft Windows SharePoint Services? How is it related to Microsoft Office SharePoint Server 2007? Windows SharePoint Services is the solution that enables you to create Web sites for information sharing and document collaboration. Windows SharePoint Services -- a key piece of the information worker infrastructure delivered in Microsoft Windows Server 2003 -- provides additional functionality to the Microsoft Office system and other desktop applications, and it serves as a platform for application development. Office SharePoint Server 2007 builds on top of Windows SharePoint Services 3.0 to provide additional capabilities including collaboration, portal, search, enterprise content management, business process and forms, and business intelligence. What is Microsoft SharePoint Portal Server? SharePoint Portal Server is a portal server that connects people, teams, and knowledge across business processes. SharePoint Portal Server integrates information from various systems into o...

SharePoint 2010 Branding: Change site actions and welcome menu arrows

Here's how you can do it. Hide the image and give our custom image element a background image. Look Like: .ms-viewselector-arrow {     background: transparent url('/PublishingImages/images/Arrow.png') no-repeat scroll 0 0;     height: 4px; /* height of the image */     width: 5px; /* width of the image */ } .ms-viewselector-arrow img {     display: none; }

Lookup field does not showing values in sharepoint2013

SharePoint Custom Form Shows HTML as Text on Lookup Fields   When creating a custom display form on SharePoint Designer, the form displays the actual HTML instead of rendering the HTML on the lookup columns. For example, see the below image: For the lookup value issue, you need to slightly modify the XSLT of the particular field from designer and add the attribute disable-output-escaping="yes" to the field.