我需要使用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);
}
答案 0 :(得分:1)
UpdateListItems操作以Xml格式返回响应,其中row
元素包含对应于列表项ID的ows_ID
属性。
如何从UpdateListItems
结果
XmlNode resultsNode = listService.UpdateListItems(strListID, batchElement);
var owsID = resultsNode.SelectSingleNode("//@ows_ID").Value;