I’ve worked a bit recently on custom field types in SharePoint for an upcoming Understanding SharePoint Journal issue. Actually, I’ve worked with custom field types for a long time, one of my first WSS3 project involved creating a cascading custom field type. Looking back I think it would have been easier, and less painfull, to eat my own eyes.
One thing that puzzled me in the beginning, which actually puzzled me still, is why you must always have two different constructors in your field type class. Just the other day a friend of mine asked about this when he looked at one of the field type classes I made for him.
public MyFieldType(SPFieldCollection fields, string fieldName)
: base(fields, fieldName)
public MyFieldType(SPFieldCollection fields,
string typeName, string displayName)
: base(fields, typeName, displayName)
The short answer is: Don’t ask.
The reason why you shouldn’t ask is that the answer cannot be made short in any situation. The answer is actually closely tied to the problems you face if you try to store custom field type properties.
As you may or may not know, storing custom properties for columns based on your field type is actually impossible, or at least incredibly difficult. The reason is that there are two different objects created from the same class that are responsible for creating a new column based on your field type. These two objects are not only completely separate objects but perform completely different tasks in the column creation operation. One objects handles the custom property input while the other object is responsible for creating the column in the list.
You’ll have to wait for the journal issue that deals with custom field types for the deep details on how custom field types work in SharePoint, but at least you should know that the two constructors are there to create two different objects.
Found this article valuable? Want to show your appreciation? Here are some options:
a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.
b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.
c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!