Checking Sharepoint UpdateListItems Xml Result

Here’s a code snippet for checking the Xml result returned from Sharepoints UpdateListItems() Lists webservice method.

private static KeyValuePair<int, string> CheckListUpdateResults(XmlNode resultsNode)
	if (resultsNode == null) return new KeyValuePair<int, string>(0, "Null results node supplied");
	XmlNamespaceManager ns = new XmlNamespaceManager(resultsNode.OwnerDocument.NameTable);
	ns.AddNamespace("sp", resultsNode.NamespaceURI);

	var errorCode = resultsNode.SelectSingleNode("//sp:ErrorCode", ns).InnerText;
	if (errorCode == "0x00000000")
		// grab the list item ID
		var owsID = resultsNode.SelectSingleNode("//@ows_ID").Value;
		return new KeyValuePair<int, string>(Convert.ToInt32(owsID), null);

	var errorText = resultsNode.SelectSingleNode("//sp:ErrorText", ns).InnerText;
	var result = new KeyValuePair<int, string>(0, string.Format("Error {0}, {1}", 
								errorCode ?? "n/a", 
								errorText ?? "n/a"));
	return result;

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

4 thoughts on “Checking Sharepoint UpdateListItems Xml Result

  1. This was helpful to get a decent error code back, but falls short in the case when multiple rows were updated in a single call to UpdateListItems.
    In that case, the code would need to be modified to return something closer to

  2. I am getting an exception as “Object reference is not set to an instancen of object” at line

    var owsID = resultsNode.SelectSingleNode(“//@ows_ID”).Value;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.