I'd like to add and select values to a choice field in a document library. Something obviously more tricky than I remembered.
I'm doing something like this but it doesn't work. The value gets added to the field in list views but not to the Choice column.
ClientContext ctx = new ClientContext("http://mymachine");
Web currentWeb = ctx.Web;
ctx.Load(currentWeb);
ctx.ExecuteQuery();
SP.List list = ctx.Web.Lists.GetByTitle("Doclib");
ctx.Load(list);
ctx.ExecuteQuery();
ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(items);
ctx.ExecuteQuery();
foreach (ListItem listItem in items)
{
ctx.Load(listItem.File);
ctx.ExecuteQuery();
if (listItem.File.Name.Equals(fileName))
{
var processValue = "A Value";
listItem["MetaProcess"] = processValue;
//SP.FieldChoice itemType = ctx.CastTo<SP.FieldChoice>(list.Fields.GetByTitle("MetaProcess"));
//itemType.Choices = new[] { "Agenda", "Agreement", "Full text", "Minutes", "News Item", "Reference" };
//itemType.Update();
//ctx.ExecuteQuery();
}
listItem.Update();
}
ctx.ExecuteQuery();