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";

or

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";

or

booleanField.DefaultValue = "1";

3 Responses to “Programmatically setting the default value of a SPFieldBoolean field”


  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…


Leave a Reply