SharePoint Web services - get choice field values Using GetList() method

Below is the code to get the values of a choice field in a sharepoint list . You can save these values into a datatable and can bind the datatable with a Drop-down control.

//get choice field values from sharepoint list
protected void GetDrpDownValuesFromList()
{
SPWebservice.Lists FMService = new SPWebservice.Lists();
FMService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode ndLists = FMService.GetList("MyList"); //add list name

XmlDocument doc = new XmlDocument();
doc.LoadXml(ndLists.OuterXml);

XmlNamespaceManager mg = new XmlNamespaceManager(doc.NameTable);
mg.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
mg.AddNamespace("z", "#RowsetSchema");
mg.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
mg.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
mg.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
mg.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");

XmlNodeList FieldsInList = doc.SelectNodes("//sp:Field", mg);

foreach (XmlNode Field in FieldsInList)
{
if (Field.HasChildNodes)
{
if (Field.Attributes["Name"].Value == "choiceFieldName")
{
foreach (XmlNode node in Field.ChildNodes)
{
if (node.HasChildNodes)
{
foreach (XmlNode Newnode in node.ChildNodes)
{
if(Newnode.HasChildNodes)
{
_addToDataTable(Newnode.InnerText); // Add node value to datatable
}
} } } } } } }

4 comments:

  1. your post is nice . . let me tell u one thing that Blogs have become latest and important source of quality free information on net people enjoying for hours together. . .nice blog keep sharing;)
    Dissertation Writing Services

    ReplyDelete
  2. Your post is very informative. You have written it very well. I will keep on coming here to check new updates. Thanks for sharing this article.
    how to write a dissertation

    ReplyDelete
  3. Thanks for writing Informative Blog. I always read from here.

    ReplyDelete
  4. Thanks for sharing the post. Can SharePoint be helpful for my essay writing website?

    ReplyDelete

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com