UpdateListItems新添加的项目ID?

时间:2014-04-09 15:22:16

标签: c# asp.net sharepoint

我需要使用UpdateListItems方法获取新添加的项列表的id 请帮忙!我需要知道id才能使用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);
}

1 个答案:

答案 0 :(得分:1)

UpdateListItems操作以Xml格式返回响应,其中row元素包含对应于列表项ID的ows_ID属性。

实施例

如何从UpdateListItems结果

中获取列表项ID
XmlNode resultsNode = listService.UpdateListItems(strListID, batchElement);
var owsID = resultsNode.SelectSingleNode("//@ows_ID").Value;