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

Get values from choice field - learningsharepoint.com/2010/07/24/get-ch....

Up vote 1 down vote favorite share g+ share fb share tw.

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 = ""; 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 object model sharepoint2010 choice link|improve this question edited Aug 27 '10 at 17:35jjnguy?37.9k1287173 asked Jun 12 '10 at 7:53Eric312.

When you read a ChoiceField in code , It will return a string array of selected choices. For example if you entered in the choice box of the column when you create it : "Company 1" ,"Company 2","Company 3 " , if user select option 1 & 2 , then returned array in code will contain "Company 1" and "Company 2" . You must change the code to the below : foreach (ListItem listItem in listItems) { string values = (string)listItem"Assigned_x0020_Company"; foreach(string s in values) { listBoxControl1.Items.

Add(s); } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions