【发布时间】:2011-04-19 17:10:11
【问题描述】:
我正在尝试将项目添加到 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>
当我设置网络参考时,它指向了正确的站点,甚至查看了 sharepoint 中的列表以确保它在那里。
【问题讨论】:
-
(1) 在
UpdateListItems周围添加try ... catch ...并检查是否有异常抛出。 (2) 这是一个添加项目的例子:msdn.microsoft.com/en-us/library/ms440289.aspx. -
是的,我已经做到了。但错误不是很有帮助。
-
结果比我想象的更有帮助。一旦我发现问题,错误就有意义了。
标签: sharepoint sharepoint-2007 caml