Question

There is a custom field in my list called "Solutions". The user can select multiple values for this field (they are in a set of checkboxes on the interface).

I get all the other values in the list with the code item.FieldValues["Solutions"].ToString(); but I'm unable to retrieve the multiple values this way.

Intellisense shows FieldValues as a dictionary entry, with the field name as key and the array as the value, but I can't parse it that way.

I've worked with the SPFieldUserValueCollection, so I know there must be a structure that will parse this out for me, but I can't find it. Can anyone point me in the right direction? Or give me a working example?

Was it helpful?

Solution

There is no specific class for storing choice field value like in case of, for example, user field value in CSOM API.

Since multiple choice field value is stored in string array, the following example demonstrates how to retrieve it:

var list = ctx.Web.Lists.GetByTitle(listTitle);
var listItem = list.GetItemById(itemId);
ctx.Load(listItem);
ctx.ExecuteQuery();
var solutions = (string[])listItem["Solutions"];
//or
var solutionsList = new List<string>((string[])listItem["Solutions"]);

foreach (var solutionValue in solutions)
{
    Console.WriteLine(solutionValue);    
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top