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
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using Microsoft.SharePoint.Security;using System.Windows.Controls;using System.Globalization;using System.Runtime.InteropServices;using System.Security.Permissions;using Email.SharePoint.WebControls;using Email.System.Windows.Controls;using System.IO;using System.Web;using System.Web.UI;namespace Email.SharePoint{ public class EmailField : SPFieldText { public EmailField(SPFieldCollection fields, string fieldName) : base(fields, fieldName) { } public EmailField(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName) { } public override BaseFieldControl FieldRenderingControl { [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)] get { BaseFieldControl fieldControl = new EmailFieldControl(); fieldControl.FieldName = this.InternalName; return fieldControl; } } public override string GetValidatedString(object value) { if ((this.Required == true) && ((value == null)|| ((String)value == ""))) { throw new SPFieldValidationException(this.Title + " must have a value."); } else { Email10ValidationRule rule = new Email10ValidationRule(); ValidationResult result = rule.Validate(value, CultureInfo.InvariantCulture); if (!result.IsValid) { throw new SPFieldValidationException((String)result.ErrorContent); } else { return base.GetValidatedString(value); } } } }}
Creating a Custom Field Type for SharePoint 2010 (Email Validation Field)
How to get all Variation Labels for SharePoint Site
hi This is giving error for using Control.Validation.WebControls; using Control.System.Windows.Controls; and using Email.sharepoint.WebControls; using Email.System.Windows.Controls; what will be the assembly for these. and post new modified one article about this Thanks vishal agarwal
Thank you for this article. I have a question. I wasn't able to get my custom field type up. I wanted to create a new title field that had the ECB menu on it. I went through your steps and just eliminated the ascx file portion so I just created the xsl and the xml file. I used the content from this post. http://blogs.msdn.com/b/chunliu/archive/2010/09/29/enabling-ecb-menu-on-a-custom-column-in-sharepoint-2010-part-2.aspx and deployed the solution on Sharepoint. I can't find my custom column type or anything. Have you ever succesfully implemented the ECB menu on a document library column?
same step you can follow instead of email field you can create a drop down.What is t he exact problem you facing?
Can you make a custom field type of dropdown type with hard code of some of list values, there is not sample in the internet so far.
Hi parameswari, Happy to see this article helped you:) Destin