Monday, May 21, 2007

Updating Sharepoint List schema's using web services

Using Microsofts UpdateList web method from (_vti_bin\lists.asmx) for both WSS2 and MOSS I couldn't figure out why I kept getting a SoapServer.SoapServerException error message (of course without any helpful explanations)

The arguments for UpdateList are :

listService.UpdateList("List_Name", ndProperties, ndNewFields, ndUpdateFields, ndDeleteFields, ndVersion.Value); //where nd is an XML Node.

Although I only wanted to add fields I was still creating all of the root elements of the nd.. parameters and then calling UpdateList only to return a SoapServerException message.
such as: XmlNode ndUpdateFields = xmlDoc.CreateNode(XmlNodeType.Element, "Fields", "") etc..

I then discovered that if I replaced the parameters for the actions I didn't need with nulls then everything sprung into life! - I couldnt find any documentation for this, however I guess thats what blogs are for!

Thus to just add new Fields use the UpdateList command in the form of:
listService.UpdateList("List_Name", ndProperties, ndNewFields, null, null, ndVersion.Value);

No comments: