I am provisioning a SharePoint site column using the object model and an xml string as follows:
using (SPSite site = new SPSite("http://myserver"))
{
using (SPWeb web = site.OpenWeb())
{
string schemaXML = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
"<Field ID=\"b6299a44-4a49-4f52-b2df-b938c15bf927\" Name=\"MyField\" Type=\"DateTime\" Required=\"True\" ReadOnly=\"False\" DisplayName=\"My Field\"" +
" StaticName=\"MyField\" ShowInNewForm=\"TRUE\" ShowInDisplayForm=\"TRUE\" ShowInEditForm=\"TRUE\" ShowInListSettings=\"TRUE\" ShowInVersionHistory=\"TRUE\" ShowInViewForms=\"TRUE\" />";
web.Fields.AddFieldAsXml(schemaXML);
web.Update();
}
}
As you can see I have set the 'Required' attribute to be true as I want to force that the Site Column should always contains data.
However after I run this code and look at the settings of the Site Column it is NOT set to required. I have used SharePoint Manager and switched it to 'required' in the settings page and it does change the 'required' attribute. I can't see any obvious problems in my provisioning xml, can anyone shed any light on why this might be happening?
Thanks, Alex