locked
Get the choices from a choice field using client object model RRS feed

  • Question

  • Hey,

    I'm trying to get the choices from a choice field using the COM and i cant seems to find a way for it.

    Using the server object model i had access to .choices of the field, but it seems its missing from COM...

    I Assume i can get the choices using the getlist method of the lists web service but im hoping there is a way to avoid it.

    Any pointers would be appriciated :)

    Thanks.

    Friday, July 16, 2010 4:07 PM

Answers

  • Hi Tropics2a,

     

    As per Waldek suggested you will need to cast your field to FieldChoice .

    below is the sample for you :

    FieldChoice myChoices = clientContext.CastTo<FieldChoice> list.Fields[ Choice FieldName ];

    myChoices .Choices will give you all choices  

    myChoices .DefaultValue  will give you the default choice

     

    Hope that helps...

    ----------

    Edited:

    Corrected SPFieldChoice  by FieldChoice for client object model...thanks  Waldek for pointing out this..!!


    MCPD (PRO: Designing and Developing Web-based Applications by Using the Microsoft® .NET Framework 2.0) MCTS (MOSS 2007 - Application Development) MyBlogs
    • Edited by AnalbenMehta Monday, July 19, 2010 9:45 PM Corrected SPFieldChoice by FieldChoice for client object model
    • Marked as answer by Aaron Han - MSFT Tuesday, July 20, 2010 1:51 AM
    Monday, July 19, 2010 7:45 PM
  • In order to retrieve the choices you should cast the Field to FieldChoice. You can then retrieve the choices using the Choices property.


    w: http://blog.mastykarz.nl | t: @waldekm | c: http://mavention.codeplex.com | c: http://mavention.nl
    Sunday, July 18, 2010 7:01 PM
  • Actually you have to use the FieldChoice class instead the SPFieldChoice. FieldChoice is the equivalent of SPFieldChoice in the Client OM.
    w: http://blog.mastykarz.nl | t: @waldekm | c: http://mavention.codeplex.com | c: http://mavention.nl
    Monday, July 19, 2010 8:33 PM

All replies

  • In order to retrieve the choices you should cast the Field to FieldChoice. You can then retrieve the choices using the Choices property.


    w: http://blog.mastykarz.nl | t: @waldekm | c: http://mavention.codeplex.com | c: http://mavention.nl
    Sunday, July 18, 2010 7:01 PM
  • Hi Tropics2a,

     

    As per Waldek suggested you will need to cast your field to FieldChoice .

    below is the sample for you :

    FieldChoice myChoices = clientContext.CastTo<FieldChoice> list.Fields[ Choice FieldName ];

    myChoices .Choices will give you all choices  

    myChoices .DefaultValue  will give you the default choice

     

    Hope that helps...

    ----------

    Edited:

    Corrected SPFieldChoice  by FieldChoice for client object model...thanks  Waldek for pointing out this..!!


    MCPD (PRO: Designing and Developing Web-based Applications by Using the Microsoft® .NET Framework 2.0) MCTS (MOSS 2007 - Application Development) MyBlogs
    • Edited by AnalbenMehta Monday, July 19, 2010 9:45 PM Corrected SPFieldChoice by FieldChoice for client object model
    • Marked as answer by Aaron Han - MSFT Tuesday, July 20, 2010 1:51 AM
    Monday, July 19, 2010 7:45 PM
  • Actually you have to use the FieldChoice class instead the SPFieldChoice. FieldChoice is the equivalent of SPFieldChoice in the Client OM.
    w: http://blog.mastykarz.nl | t: @waldekm | c: http://mavention.codeplex.com | c: http://mavention.nl
    Monday, July 19, 2010 8:33 PM
  • Thanks guys it worked!

    truly appriciated.

    Tuesday, July 20, 2010 12:10 PM
  • Thanks. Your answer was very helpful.

    However, I couldn't get it to work until I added () around list.Fields[ChoiceFieldName].

    Wednesday, July 20, 2011 4:21 AM