Creating Custom Field Types

While SharePoint allows you to create many different types of site columns, you will find yourself at times creating custom site column types. For example, you may want to create a new site column type that displays a drop-down list that gets data from the database or some other source. To create a custom site column type you need to create the following:

• A new field type class. This is a class that must inherit from Microsoft.SharePoint.SPField or one of its inherited classes.

• A new field type definition. This is defined in an XML file that has a naming convention such as fldTypes_*.xml and is deployed to <14 hive>TemplateXML. The field definition file tells SharePoint information related to the field type such as the name of the field and the underlying parent field type.

• A new custom field control. This is a class that inherits from the BaseFieldControl or one of its inherited classes and defines the user interface of the field type.

In this section you create a new field type called Country Drop Down List. This field control simply renders a drop-down list that displays a list of 10 countries. For now, you will hard code this list. You could also get the data from a database or some other source, but for now you should see how to write the new field type.

You can also create the site column using features. Note that the value of the TypeName is used for the type attribute in the field element when creating a site column of this field type using features. The following is an example of the Field element you use to create a new site column:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field Type=" CountryDropDownList"
   DisplayName="Countries" Required="FALSE"
   Group="Custom Columns"
   ID="{410BCF29-E156-4256-91E7-CCFED3482DAC}"
   StaticName=" Countries" Name=" Countries" />
</Elements>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset