I have a custom contenttype. This contenttype is inherited some columns from the OOTB contenttype "ArticlePage". I would like to set one of these columns required in my custom contenttype. How to do that programmatically? I am talking about the column "ArticleStartDate".
1 Answer
SPContentType contentType = curWeb.ContentTypes["Custom CT Name"];
SPField field = contentType.Fields["ArticleStartDate"];
contentType.FieldLinks[field.Id].Required = true;
contentType.Update();
Use the FieldLinks property of the contenty type. There are quite a lot of examples explaining using this property. Refer msdn as well : FieldLinks
-
"ArticleStartDate" is an internal name, I assume. So the code would be: contentType.Fields.GetFieldByInternalName("ArticleStartDate"); Commented Sep 8, 2015 at 7:50