In this article, I am describing how to create a custom field type for SharePoint 2010. I have searched the internet but didn't find any relevant documentation for this. Here I am creating a simple field type for Email validation; it will accept only valid email addresses.
First, we start with the project
Creating Visual Studio Project
- In Visual Studio, create an Empty SharePoint Project. Give a suitable name for your project

- Right-click the project name in Solution Explorer and select Properties.

- On the Application tab of the Properties dialog, enter Email.SharePoint.ISBN_Field_Type as the Assembly name and Email. SharePoint as the Default namespace. Leave the Target framework set to .NET Framework 3.5.

- Click Save
- Right-click the project name in Solution Explorer and select Add | New Item
- In the Add New Item dialog box, select Visual C#
- Select Class from the template and give name as Email.Field.cs

- Create two classes (in the same way as described) named Email.FieldControl.cs and EmailValidationRule.cs
- In Solution Explorer, right-click the project name and select Add, then SharePoint Mapped Folder
![customfield5.gif]()
- Use the tree control that opens to map the folder to TEMPLATE\ControlTemplates and click OK.
![customfield6.gif]()
- Right-click the new ControlTemplates folder (not the project name) in Solution Explorer and select Add | New Item
- In the Add New Item dialog box, select SharePoint | 2010 in the Installed Templates tree
- Select a SharePoint User Control in the Templates box, and give the ascx file the name EmailControl.ascx. Click Add. Visual Studio automatically adds the file to the SharePoint Solution manifest and sets it to be deployed to ProgramFiles\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\ControlTemplates. It also at this time adds the assembly to the manifest and sets it to be deployed to the Global Assembly Cache (GAC).
![customfield7.gif]()
- Delete the EmailFieldControl.ascx.cs and ISBNFieldControl.ascx.designer.cs files that are created automatically under the EmailFieldControl.ascx file. They are not needed for this project. The default content of EmailFieldControl.ascx refers to the EmailFieldControl.ascx.cs file you just deleted and, if you build the project at this point, the compiler will give you a warning about the missing file. Ignore it; no need to worry about it.
![customfield8.gif]()
- In Solution Explorer, right-click the project name and select Add, then SharePoint Mapped Folder.
![customfield9.gif]()
- Use the tree control that opens to map the folder to TEMPLATE\XML and click OK.
![customfield10.gif]()
- Right-click the new XML folder (not the project name) in Solution Explorer and select Add | New Item.
- In the Add New Item dialog box, select Visual C# and select an XML file; give the name as Fldtypes_EmailField.xml.
![customfield11.gif]()
- In Solution Explorer, right-click the project name and select Add, then SharePoint Mapped Folder.
- Use the tree control that opens to map the folder to TEMPLATE\LAYOUTS\XSL and click OK.
![customfield12.gif]()
- Right-click the new XSL folder (not the project name) in Solution Explorer and select Add | New Item.
![customfield13.gif]()
- In the Add New Item dialog box, select Visual C# then select XSLT File in the Templates window.
![customfield14.gif]()
- In the Name box, type fldtypes_EmailField.xsl and click Add. Note this is very similar to the name of the previous file you created. The two files have different purposes and are deployed to different folders.
- Right-click the References node in Solution Explorer, click Add Reference, and select PresentationFramework.dll on the .NET tab in the Add Reference dialog box. Click OK.
Creating the Validation Rule Class
- Open the EmailValidationRule.cs file and add the following statements.
- Replace the class declaration with the following code.
Creating the Custom Field Class
- Open the Email.Field.cs file.
- Add the following name spaces.
- Add the following statements. These enables our class implementation to reference other classes you create in later steps. Until you create those classes you may see compiler warnings about these statements. Don't worry about that; we are moving to that in a following step.
- Please find the following updated code.
Creating the Field Rendering Control
Please replace the code in EmailFieldControl.ascx.cs we created in step 20 with the following.
Creating the Field Rendering Template
- Open the EmailControl.ascx file.
- The following directives are already in the file.
- Below this markup is a <%@ Control directive that makes reference to files that you deleted in an earlier step and contains other attributes that are not used in this project. Replace it with the following simplified directive. I have already done this change in the above code.
Creating the Field Type Definition
- In Visual Studio, build the project. The project is not finished, but you need to do a build at this time to generate a GUID and a Public Key Token for the assembly.
- Open the fldtypes_EmailField.xml file and replace it's contents with the following markup
Creating the XSLT Style sheet
Open the fldtypes_EmailField.xsl file and replace the code.
Build and Test the Custom Field Type
- Select Deploy on the Build menu. This automatically rebuilds the assembly, deploys the assembly to the GAC, deploys the ascx file to %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\ControlTemplates, deploys the fldtypes*.xml file to %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\XML, deploys the fldtypes*.xsl file to %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL, and recycles the Web application.
- Go to site actions -->Site Settings
- Click on site libraries and list
![customfield15.gif]()
- Click on Create new Content
- Create a custom list named Test For Email
![customfield16.gif]()
- From the ribbon click on create column
![customfield17.gif]()
- You will see that our custom field is added there successfully. Give the details as shown below to add a custom column to your list.
![customfield18.gif]()
- From the screen shot shown below you can see our custom email field in action.
![customfield19.gif]()
![customfield20.gif]()
The data is added as shown below.
![customfield21.gif]()
For more details, you can refer to the article of creating custom field for SharePoint 2010 in MSDN.