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); } } } }}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: