Creating Custom SharePoint 2010 Field Types
Summary: Learn how custom field types provide a powerful extensibility point for creating business solutions for Microsoft SharePoint 2010. Learn how to make a more polished column type by using custom logic to create default values and validate user input.
Applies to: SharePoint Foundation 2010 | SharePoint Server 2010 | Visual Studio | Visual Studio 2008 | Visual Studio 2010
Provided by: Ted Pattison, Critical Path Training, LLC (SharePoint MVP)
Although site columns provide users and developers with new capabilities in reuse, you can define a reusable column definition that is even more powerful. With Microsoft SharePoint Foundation 2010, you can drop down to a lower level by creating custom field types.
The procedure that is demonstrated in this Microsoft SharePoint Visual How To provides a simple example of how to create a custom field type for a product code. The following are the high-level steps that are required to create a custom field type.
To create a custom field control
Creating the Custom Field Class
You must define the custom field class as public, and it must provide two nondefault constructors. This example also demonstrates how to validate field values using a regular expression by overriding the GetValidatedString method.
Creating the Field Type Deployment File
The Field Type Deployment file contains a Collaborative Application Markup Language (CAML) definition of the custom field type. You must name this file following the pattern of fieldtypes*.xml and then deploy it in the 14\TEMPLATE\XML directory. The file in this example is named fldtypes_WingtipCustomFields.xml.
The SharePoint development tools in Microsoft Visual Studio 2010 let you use the $SharePoint.Project.AssemblyFullName$ token in place of the actual assembly name. The SharePoint tools replace this token with the assembly name when you compile your source files into a solution package.
When you learn how to create a custom field type, you have the most control that SharePoint Foundation 2010 offers for creating a polished user interface for users to display and edit column values. Developing custom field types also provides you with a powerful new way to perform data validation before allowing user input values to be written to the content database.
> [!VIDEO https://www.microsoft.com/en-us/videoplayer/embed/bd82a836-7ef7-4e22-8aaa-7821dcd90cda]
About the Author
Ted Pattison is an author, instructor, and co-founder of Critical Path Training, a company dedicated to education on SharePoint technologies. As a Microsoft SharePoint Most Valuable Professional (MVP), Ted frequently works with the Microsoft Developer Platform Evangelism group to research and author SharePoint training material for developers early in the product life cycle while in its alpha and beta stages. Ted is also co-author of Inside Microsoft SharePoint 2010.