0

I am attempting to read the property of the Item content type which shows the Required, Hidden or Optional property for a particular column.

 if (spList.TryFindContentType("Item", out SPContentType itemContentType))
 {
     foreach (var field in itemContentType.Fields)
     {
         // How do I access the status value for a particular column? E.g. Hidden, Required or Optional?
     }
 }
0

For the columns in a Content Type eg "Item" Content Type, you could use the code snippet below to get it directly:

 using (SPSite site =new SPSite("http://demoaam.contoso2016.com/sites/dev/"))
        {
            SPWeb web = site.OpenWeb();
            SPList list = web.Lists["TestList"];
            foreach (SPListItem item in list.Items)
            {
                Console.WriteLine("Title " + item["Title"]);
                Console.WriteLine("Column Name 1 "+ item["Col_x0020_Name_x0020_1"]);
            }
        }

enter image description here

Field is hosted in Item Object, use item[internal field name] will get the field value.

enter image description here

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.