Working with content types
A Content Type Definition (CTD) is an XML-format configuration file for content types. After creating a new CTD the content type is immediately available in the system and can be used to create new content. The XML configuration (CTD) holds information about the content's name, description, icon, its parent content type's name and fields for storing content metadata.
Create a new content type definition
First login to the admin-ui and go to the Content Types menu. There you can find all the available content types, built-in and the custom ones as well. Choosing an existing content type to be your custom's parent type is a key step of creating content types in sensenet. It can save you a lot of headaches if you choose a parent type with fields and logic which you will need in your custom type anyway.
Let's see how to create a custom type for contracts. Contracts are in most of the cases files with some specific metadata like multiple unique contract id's, a connected project or lawyer name and related other documents as references. But behind these contract-specific data they are files that should have all the common metadata like the actual binary of the file, date of modification, creator user and so on. These are the cases when sensenet's content type inheritance comes handy. All you have to do is to choose the right parent type and create an inherited one to get all the common fields that a file typed content should have.
Click on the add button at the top of the drawer menu and choose Content Type from the dropdown. A xml editor will appear with some default data to help you at the start. Don't panic, working with these xml files seems to be though at the beginning, but you cannot spoil anything and if you made one, the others will come easy.
You can clear the content of the editor and paste the following xml instead:
<ContentType name="Contract" parentType="File" handler="SenseNet.ContentRepository.File" xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition"><DisplayName>Contract</DisplayName><Description>Type for agreement documents</Description><Icon>File</Icon><Fields><Field name="ContractId" type="ShortText"><DisplayName>Contract Id</DisplayName><Description>Unique contract Id needed for example for legal proceedings</Description><Configuration><MaxLength>30</MaxLength><MinLength>10</MinLength><Regex>[a-zA-Z0-9]*$</Regex><Compulsory>true</Compulsory></Configuration></Field><Field name="RelatedProject" type="Reference"><DisplayName>Related project</DisplayName><Description>Project to which the contract relates</Description><Configuration><AllowMultiple>false</AllowMultiple><AllowedTypes><Type>ProjectWorkspace</Type></AllowedTypes></Configuration></Field><Field name="ContractValue" type="Number"><DisplayName>Contract value</DisplayName><Description>Value of the contract</Description><Configuration><Digits>2</Digits></Configuration></Field><Field name="RenewalDate" type="DateTime"><DisplayName>Renewal date</DisplayName><Description>The date of renewal of the contract</Description></Field></Fields></ContentType>
See followings to understand what is happening here:
<ContentType name="Contract" parentType="File"..>
You've created a content type named Contract that is inherited from the built-in type File. That means that all the fields and configurations from parent type File are available on Contract type as well (in the next paragraph you can see which are these) and you have to define only those fields that are required on Contract and are not part of File's fieldset.
...<DisplayName>Contract</DisplayName><Description>Type for agreement documents</Description><Icon>File</Icon>...
In the head part of the CTD we define key descriptive things that will be used on various places on the UI where we will use the type itself.