1

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();

2 Answers 2

0

Did select to work in another route using the Camelot .NET Connector for SharePoint instead!

-2

the following works for me.

    calendarDropDown = (DropDownList)TemplateContainer.FindControl("calendarDropDown");
    if (ControlMode == SPControlMode.New || ControlMode == SPControlMode.Edit)
    {
        SPWeb currentWeb = SPContext.Current.Web;
        SPListCollection lists = currentWeb.Lists;
        foreach (SPList list in lists)
        {
            if (list.BaseTemplate == SPListTemplateType.Events)
            {
                calendarDropDown.Items.Add(list.Title);
            }
        }
    }
2
  • And this will run in ClientContext? May 7, 2012 at 21:25
  • This is not a code with ClientContext, but with classic server side object model
    – Steve B
    Jun 21, 2012 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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