Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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();
share|improve this question
add comment

2 Answers 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);
            }
        }
    }
share|improve this answer
    
And this will run in ClientContext? –  Eric Herlitz May 7 '12 at 21:25
    
This is not a code with ClientContext, but with classic server side object model –  Steve B Jun 21 '12 at 9:36
add comment
up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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