调用 UpdateListItems 时必须填写 ID。请参阅MSDN中的 Cmd="New" 示例。
因此,在您的情况下,将 Batch 元素更改为:
var batch = "<Batch OnError=\"Continue\"><Method ID=\"1\" Cmd=\"New\">" +
"<Field Name=\"Title\">" + title + "</Field>" +
"<Field Name=\"ID\">" + New + "</Field>" +
"</Method></Batch>";
其中 New 是一个虚构的 ID。您仍然需要解析真实 ID 的结果,就像您已经在做的那样。
以下是对 SP2010 服务器列表的请求示例:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>Announcements</listName>
<updates>
<Batch OnError="Continue">
<Method ID="1" Cmd="New">
<Field Name="ID">998877</Field>
<Field Name="Title">abcdef</Field>
</Method>
</Batch>
</updates>
</UpdateListItems>
</soap:Body>
</soap:Envelope>
和回应:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<UpdateListItemsResult>
<Results>
<Result ID="1,New">
<ErrorCode>0x00000000</ErrorCode>
<ID />
<z:row ows_ID="6" details="removed" xmlns:z="#RowsetSchema" />
</Result>
</Results>
</UpdateListItemsResult>
</UpdateListItemsResponse>
</soap:Body>
</soap:Envelope>