Here’s something I couldn’t seem to find documented anywhere…
If you’ve programmatically created a new Yes/No field and added it to SharePoint, you don’t want to set the default value like this:
booleanField.DefaultValue = "No";
booleanField.DefaultValue = "Yes";
Doing so caused the following error when I was trying to create folders programmatically in the List that was inheriting the Content Type with that field.
Microsoft.SharePoint.SPException: Invalid Yes/No value
A Yes/No field contains invalid data. It should be either 1 or 0. Please check the value and try again.
That made me scratch my head for a while since the property takes a string and the values in the UI when you set it is Yes or No. How you should set that property is:
booleanField.DefaultValue = "0";
booleanField.DefaultValue = "1";
Again one of those big annoyances in SharePoint. Just like sometimes guids must be provided including brackets, the other time without brackets, of sometimes in CAML that there is a difference between true and TRUE… Welcome to the world of SharePoint…
Had the (almost) same experience! http://community.zevenseas.com/Blogs/Robin/archive/2008/10/21/fields-hidden-from-the-newform-should-have-defaultvalues-set-otherwise-.aspx 😉
Thanks for the heads up. Here’s a similar post for SPFieldLookup fields: