Update Choice field through Web Service

Updating the choices in a choice column is easy through SharePoint web services.

//Get the service ready
listsWS.Lists wsList = new listsWS.Lists();
wsList.Credentials = new System.Net.NetworkCredential("username", "password","domain");
wsList.Url = strWebSiteURL;

//Prepare the node for updating SharePoint Choice Column/field

XmlDocument xmlDocField = new System.Xml.XmlDocument();
System.Xml.XmlElement xFields = xmlDocField.CreateElement("Fields");
xFields.SetAttribute("OnError", "Continue");

StringBuilder strChoice = new StringBuilder();
//Define the attributes for fields and in case of any errors, try defining all fields

//Notice the capital name of nodes
strChoice.Append("Option 1");
strChoice.Append("Option 2");
strChoice.Append("Option 3");

xFields.InnerXml = strChoice.ToString();

//Call the UpdateList Method
XmlNode xResultUpdateField = wsList.UpdateList("List Name", null, null, xFields, null, null);

No comments:

Post a Comment