1

Is it possible to get the available options on a choice field from the FieldCollection object? I am using a LINQ statement and have no issues getting other properties such as internal name, the field type, etc. Can I get the choices for choice fields in a similar way?

FieldCollection fc = //logic to get field collection
var fieldData = fc.Select(d => new 
{
    Title = d.Title,
    InternalName = d.InternalName,
    FieldTypeString = d.TypeAsString,
    //FieldChoices = ??
});
1

please load the Choices by using internal name of the field and get the choices

           ClientContext context = new ClientContext(source_site_url);
           List list = context.Web.Lists.GetByTitle(list_name);
           Field choice = list.Fields.GetByInternalNameOrTitle("jobtitle");     
           FieldChoice fldChoice = context.CastTo<FieldChoice>(choice);
           context.Load(fldChoice, f => f.Choices);
           context.ExecuteQuery();
           foreach (string item in fldChoice.Choices)
           {
               control_name.Items.Add(item.ToString());
               //add choices to dropdown list
           }

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.