Creating Custom Field Types in SharePoint using Visual Studio

Here we are planning to create a Custom field will auto populate with the logged in user information. First we need create project with SharePoint assembly as reference. For this create empty SharePoint Application project.
> Start Visual Studio.
> On the File menu, click New, and then click Project.
> In the Project Types pane of the New Project dialog box, select Visual C#, and then select the SharePoint category.
>In the Templates pane, click Empty. Specify a Name and Location for the project, and then click OK. Visual Studio creates a solution that contains an empty project.

Visual Studio Extensions for Windows SharePoint Services 3.0 provides support
for creating SharePoint field types through the Field Control project item.


Now we need to add a Field Control to the Project we have created.

> In the Visual Studio Solution Explorer, right-click the empty project created in the previous procedure, click Add, and then click New Item.
> In the Categories pane of the Add New Item dialog box, expand the Visual C# Project Items node, and then select the SharePoint category.
> In the Templates pane, click Field Control. Specify LoginInfoID for the Name of the field control, and then click Add. Visual Studio adds the new field control to the project.

Visual Studio adds two Microsoft Visual C# code files to the project: LoginInfoID.FieldControl.cs and LoginInfoID.Field.cs. The LogoField.Field.cs file contains code that defines a class that by default is derived from the SPFieldText class and that overrides the FieldRenderingControl property.

Now write the custom logic inside the LoginInfoID.FieldControl.cs file. Refer the this full source attached in this blog for understand the remaining. Download Source Code

Now the field control xml file and deployment.
The XML file must be named in the format fldtypes*.xml (for example, fldtypes_customfield.xml) and placed in Local_Drive:\\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML
Upload all the .dll files into the Drive:\WINDOWS\assembly folder
At a command prompt, type iisreset to reset Internet Information Services (IIS).
In a view of the list to which you want to add the custom field type, click Settings, and then click Create Column.
Result as shown screenshot


Comments

Madhukar Singh said…
Thanks friend,

I was looking how to create MOSS costume field using VS 2008. Thanks
dan rogy said…
My current project requires ability to display choice column value via color or image associated with a choice

But Sharepoint standard packaged misses that control

I am looking for available solutions on market

I came across

http://sharepointfields.com

Does anybody has experiece using it?
fEi said…
Hi nice post. I have question on how to set the custom field type when creating a field using Visual Studio?

E.g.

list.Fields.Add("Location", SPFieldType.Note, true);
list.Update();

SPFieldType.?

Thanks in Advance.

Popular posts from this blog

ASP.NET website "Cannot read configuration file due to insufficient permissions" in IIS 7 and Windows Server 2008

Error occurred in deployment step 'Install app for SharePoint': The System Account cannot perform this action.

None of the selected features can be installed or upgraded. Setup cannot proceed since no