我正在尝试向 Sharepoint 中的列表添加一个项目。目前我正在尝试通过 CAML 添加项目
我可以阅读列表并查询列表,但我无法添加到列表中。我看到的所有示例都更新了列表,我希望添加项目应该是相当相似的过程。
这就是我目前测试它的方式。
SPLists 是对 http:///_vti_bin/lists.asmx 的网络引用
void Test(){
var listService = new SPLists.Lists();
string strBatch ="<Method ID='1' Cmd='New'><Field Name='Title'>Test</Field></Method>";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "1");
elBatch.InnerXml = strBatch;
XmlNode ndReturn = listService.UpdateListItems("TestList",elBatch);
Console.Write(ndReturn.OuterXml);
Console.WriteLine("");
}
someone already asked a similar/same question here 关于 SO 但没有回答
编辑
这是我得到的错误
<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Result ID="1,New">
<ErrorCode>0x81020026</ErrorCode>
<ErrorText>The list that is referenced here no longer exists.</ErrorText>
</Result>
</Results>
当我设置 Web 引用时,它指向了正确的站点,甚至查看了 sharepoint 中的列表以确保它在那里。
最佳答案
看起来您可能需要在 strBatch ( use this article as a reference ) 中添加一些小内容: <Field Name='ID'>New</Field>
这意味着你会有类似的东西:
string strBatch ="<Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='Title'>Test</Field></Method>";
此外,如果您的列表中有任何必填字段,您可能也必须指定这些字段。
关于sharepoint - 将 ListItem 添加到 Sharepoint 2007 中的列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3836981/