Share via


How to: Create a Custom Field Type Definition

Applies to: SharePoint Foundation 2010

A field type definition is an XML file named on the pattern fldtypes*.xml that is deployed to the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\XML. The field types that ship with SharePoint Foundation are located in the FLDTYPES.XML file. A field definition file contains the information that SharePoint Foundation needs to correctly render the field in list views, and on the Display, Edit, and New forms. The name and description of the field type, as it appears on such UI pages as the Customize [list] page, the New Site Column, and the Create Column pages, is also configured in the field type definition. Most importantly, the definition contains information about the assembly that contains the compiled field type.

In order to recognize a custom field type, SharePoint Foundation must have a field type definition in a fldtypes*.xml file. You create these files in Visual Studio as part of a custom field type project. For example, if you had a field type definition for a field type that defined an American Social Security number, you might name the XML file fldtypes_ssn_Contoso.xml.

Note

We recommend that you follow a systematic naming pattern and include your company name so that your field definitions in the ... \XML directory can be distinguished easily from those of other solution providers. It is possible to have more than one field definition in the same file (as in the example below) and this can be a sensible policy when you have several field types that you know will always be deployed together. But for the sake of simplicity in instructions, the SharePoint Foundation SDK generally assumes that there is just one custom field type in each custom fldtypes*.xml. The FLDTYPES.XML that ships with SharePoint Foundation has many field type definitions. Modifying that file is not supported.

The following is a list of the elements included the field type definition. Click the element name for detailed information about that element.

  <FieldTypes Element (Field Types)>

The top level container element for the fldtypes*.xml file.

    <FieldType Element (Field Types)>

The top level container element for a field type definition.

      <Field Element (Field Types)>

An element that represents a single characteristic of the field type.

      <PropertySchema Element (Field Types)>

An element that defines variable field type properties. Obsolete.

        <Fields Element (Field Types Property Schema)>

The top-level container element within a PropertySchema element. Obsolete.

          <Field Element (Field Types)>

An element that represents a variable property of a custom field type that is set when a column based on the field type is created. Obsolete.

            <Default Element (Field Types Property Schema)>

An element that represents the default value of a property of a custom field type. Obsolete.

      <RenderPattern Element (Field Types)>

An element that defines how the field is rendered in certain circumstances. Obsolete.

Field Types Definition Example

The following example defines two custom field types.

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
  <FieldType>
    <Field Name="TypeName">SocialSecurityNumber</Field>
    <Field Name="ParentType">Text</Field>
    <Field Name="TypeDisplayName">Social Security Number</Field>
    <Field Name="TypeShortDescription">Social Security Number (123456789, 123-45-6789)
    </Field>
    <Field Name="AllowBaseTypeRendering">TRUE</Field>
    <Field Name="FieldTypeClass">
      AdventureWorks.FieldTypes.SSNField, AdventureWorks.FieldTypes,
      Version=1.0.0.0,Culture=neutral,PublicKeyToken=90734cc53324b79c
    </Field>
  </FieldType>
  <FieldType>
    <Field Name="TypeName">USAddress</Field>
    <Field Name="ParentType">MultiColumn</Field>
    <Field Name="TypeDisplayName">US Address</Field>
    <Field Name="TypeShortDescription">US Address(12345 NE 123 St. Redmond, WA 98052)
    </Field>
    <Field Name="UserCreatable">TRUE</Field>
    <Field Name="FieldTypeClass">
      AdventureWorks.FieldTypes.USAddressField, AdventureWorks.FieldTypes,
      Version=1.0.0.0,Culture=neutral,PublicKeyToken=90734cc53324b79c
    </Field>
  </FieldType>
</FieldTypes>

Field Type Definitions in the Object Model

After you deploy a field type solution, you can access the field type definition in the SharePoint Foundation object model as an SPFieldTypeDefinition object. Most of the settings you define in the field type definition XML are represented as read-only members of the SPFieldTypeDefinition class. Most of the properties of this class have the same name as the corresponding setting in the fldtypes*.xml file. See Field Element (Field Types) for details of the exceptions.

Both the RenderPattern and the PropertySchema are Obsolete. The RenderPattern element is not accessible through SPFieldTypeDefinition. The PropertySchema element is readable in the PropertySchema property as an XML string.

See Also

Tasks

Walkthrough: Creating a Custom Field Type

Concepts

Custom Field Types

How to: Create a Custom Field Class

Custom Field Type Property Rendering