0
votes

I know a similar question has already been asked, but that retrieves all the items for Choice field using Sharepoint Object Model. I dont have object model available to me. I want to do this using CAML or something. I couldnt figure out a CAML query to get all the items for a choice field.

Any pointers in the right direction will be really appreciated.

Regards.

2

2 Answers

1
votes

Can you use web service calls? This thread explains reading multi-choice choices from a web service: http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/04a00936-7102-4ddc-aa7d-0be7e14e7692 This follow-up post might be useful, too: http://mysharepointwork.blogspot.com/2009/10/sharepoint-web-services-get-choice.html

1
votes

There is actually another way of getting the values using Xelements

            using (var service = new SharePoint.Services.ListsSoapClient())
            {
                service.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

                var listName = "MyList";

                var xelement = service.GetList(listName);
                var fieldName = "Category"; //My Field name
                XNamespace ns = "http://schemas.microsoft.com/sharepoint/soap/";

                var selectedField = xelement.Descendants(ns + "Fields").Elements().Where(x => x.Attribute("Name").Value == fieldName).FirstOrDefault();
                if (selectedField != null)
                {
                    var choices = selectedField.Elements(ns + "CHOICES").Elements().Where(x => x.Name == ns + "CHOICE").Select(x => x.Value).ToList();
                    //Do something with choices
                }
            }