In Sharepoint 2010, is there a way to create a new column for a Document Library using the web services API?
2 Answers
Yes, you can use the UpdateList method of the Lists.asmx web service. See http://msdn.microsoft.com/en-us/library/lists.lists.updatelist(v=office.12).aspx for more details (this is from 2007, but still works in 2010).
You will basically use XML to add/remove columns using the Field schema. There is a code example on that page.
Is using the web service a requirement? Otherwise, you can use the SharePoint CSOM to add a field to a list:
example in javascript:
function addFieldToList() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Announcements');
this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'MyField\' Type=\'Number\' />', true, SP.AddFieldOptions.defaultValue);
var fieldNumber = clientContext.castTo(oField,SP.FieldNumber);
fieldNumber.update();
clientContext.load(oField);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
Refer to this MSDN page for more info about the javascript CSOM or to this page for the .NET version.
-
1Thanks for the response. The requirement is to make the call from a Java application so using the web service appears be best.Reynard– Reynard2014-01-17 18:35:17 +00:00Commented Jan 17, 2014 at 18:35