Akatsuki Leader
Akatsuki Leader

Reputation: 23

UpdateListItems newly added item id?

i need to get the id of the new added item list using UpdateListItems method please help! i need to know the id in order to be able to use addattachment()

sitesWebServiceLists.Lists listService = new sitesWebServiceLists.Lists();


listService.Credentials =
System.Net.CredentialCache.DefaultCredentials;

listService.Url = "http://MyServer/sites/MySiteCollection/_vti_bin/Lists.asmx";

System.Xml.XmlNode ndListView = listService.GetListAndView("MyList", "");
string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
batchElement.SetAttribute("OnError", "Continue");
batchElement.SetAttribute("ListVersion", "1");
batchElement.SetAttribute("ViewName", strViewID);

batchElement.InnerXml = 
   "</Method><Method ID='1' Cmd='New'>" +
   "<Field Name='Title'>Added item</Field></Method>";

/*Update list items. This example uses the list GUID, which is recommended, 
but the list display name will also work.*/
try
{
   listService.UpdateListItems(strListID, batchElement);
}
catch (SoapServerException ex)
{
   MessageBox.Show(ex.Message);
}

Upvotes: 1

Views: 1106

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59338

UpdateListItems operation returns response in Xml format, where row element contains ows_ID attribute which corresponds to list item ID.

Example

How to grab the list item ID from UpdateListItems result

XmlNode resultsNode = listService.UpdateListItems(strListID, batchElement);
var owsID = resultsNode.SelectSingleNode("//@ows_ID").Value;

Upvotes: 1

Related Questions