Sharepoint Client Object Model (CSOM) Get Choice Field Values

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public string[] GetChoiceFieldValues(string listName, string fieldName)
{
    using (ClientContext clientContext = new ClientContext("your site url")
    {
        List<portalfile> fileList = new List<portalfile>();
 
        var domain = "domain";
        var username = "username";
        var password = "password";
        clientContext.Credentials = new NetworkCredential(username, password, domain);
 
        Web web = clientContext.Web;
        var list = web.Lists.GetByTitle(listName);
        clientContext.Load(list, d => d.Title);
        clientContext.ExecuteQuery();
 
        var field = clientContext.CastTo<FieldChoice>(list.Fields.GetByInternalNameOrTitle(fieldName));
        clientContext.Load(field, f => f.Choices);
        clientContext.ExecuteQuery();
 
        return field.Choices;    
    }
}


HTH,
Andreas

Comments

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

CRM Plugin - Parent and Child Pipeline