How to read a Choice Field from Sharepoint 2010 Client Object Model

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2010-06-12T07:53:05Z Indexed on 2010/06/12 8:03 UTC
Read the original article Hit count: 644

Filed under:
|
|
|
|

Hello,

I'm using Sharepoint 2010 Object Model. I'm trying to retrive the content of a Custom List. Everything works fine except if when I try to retrieve a Choice Field.

When I try to retrieve the choice field, I got an PropertyOrFieldNotInitializedException exception...

Here is the code I'm using:

            ClientContext clientContext = new ClientContext("https://mysite");
            clientContext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("aaa", bbb");
            clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

            List list = clientContext.Web.Lists.GetByTitle("mylist");
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View/>";

            ListItemCollection listItems = list.GetItems(camlQuery);
            clientContext.Load(listItems);
            clientContext.ExecuteQuery();

            foreach (ListItem listItem in listItems)
            {

                listBoxControl1.Items.Add(listItem["Assigned_x0020_Company"]);

            }

Thank you for you help!

Eric

© Stack Overflow or respective owner

Related posts about sharepoint

Related posts about object