UpdateListItems新添加的项id
本文关键字:id 添加 新添加 UpdateListItems | 更新日期: 2023-09-27 17:57:40
我需要使用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);
}
UpdateListItems操作以Xml格式返回响应,其中row
元素包含与列表项ID对应的ows_ID
属性。
示例
如何从UpdateListItems
结果中获取列表项ID
XmlNode resultsNode = listService.UpdateListItems(strListID, batchElement);
var owsID = resultsNode.SelectSingleNode("//@ows_ID").Value;