How to update a content type programmatically

sharepoint

i want to modify the "Required" property of a field of a list which is associated to a content type.
i've modified the content type and schema of the list, but the "Required" is still set to true, i want it to be optional.

Any idea ?

thanx

Best Answer

Try like this:

private void SetFieldRequired(SPList list, string field, string contentType, bool required)
{
    SPField fieldInList = list.Fields[field];
    fieldInList.Required = required;        
    fieldInList.Update();

    SPField fieldInContentType = list.ContentTypes[contentType].Fields[field];
    fieldInContentType.Required = required;
    fieldInContentType.Update();
}

Don't forget to add some exception handling.

Related Topic