Retrieve all items from a SharePoint Field Choice Column with using ObjectModel
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 i开发者_如何学JAVAtems for a choice field.
Any pointers in the right direction will be really appreciated.
Regards.
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
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
}
}
精彩评论