将 ListItem 添加到 Sharepoint 2007 中的列表

发布于 2024-09-25 12:18:13 字数 1307 浏览 3 评论 0原文

我正在尝试将项目添加到 Sharepoint 的列表中。目前我正在尝试通过 CAML 添加项目

,我可以读取列表并查询列表,但我无法添加到列表中。我见过的所有示例都会更新列表,我希望添加项目的过程应该相当相似。

这就是我目前正在测试的方式。 的 Web 参考

    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("");

}

SPLists 是对 http:///_vti_bin/lists.asmx 有人已经在这里提出了类似/相同的问题,但没有得到回答

编辑
这是我收到的错误


<结果 ID="1,新">
<错误代码>0x81020026
此处引用的列表不再存在。

当我设置 Web 参考时,它会将其指向正确的站点,甚至查看共享点中的列表以确保它在那里。

I am trying to add an item to a list in Sharepoint. At the moment I am trying to add the item via CAML

I can read the list, and query the list but I have not been able to add to the list. All the examples that I have seen update the list, I would expect that it should be reasonably similar process to add an item.

this is how I am testing it at the moment.
SPLists is a web reference to 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 on SO but not answered

Edit
This is the error that I get

<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>

When I setup the web reference pointed it at the correct site and even looked at the list in sharepoint to make sure that it is there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨洒年华 2024-10-02 12:18:13

看起来您可能需要在 strBatch 中添加一点内容(使用本文作为参考): New

这意味着您将得到如下内容:

string strBatch ="<Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='Title'>Test</Field></Method>";

另外,如果您的列表中有任何必填字段,您可能也必须指定这些字段。

Looks like you probably need a small addition to your strBatch (use this article as a reference): <Field Name='ID'>New</Field>

Which means you'll have something like:

string strBatch ="<Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='Title'>Test</Field></Method>";

Also, if you have any required fields on your list, you'll probably have to specify those as well.

心的憧憬 2024-10-02 12:18:13

这就是我发现解决了我的问题的方法。

当我在 Visual Studio 中设置 Web 参考时,我将其指向 http://sharepointSite/subweb1/ subweb2/_vit_bin/lists.asmx 作为参考。

然而,当我今天回去检查时,它指向 http://sharepointSite/_vit_bin/lists.asmx 。手动将其更改回 http://sharepointSite/subweb1/subweb2/_vit_bin/lists.asmx 在 app.config 文件中,一切都变得不同了。

@Kit +1 我也添加了你的建议。根据您的建议和我在网络参考中发现的信息,它第一次起作用了。

我最终只是创建了一个只有 1 个字段(标题)的子网站以使其正常工作。

This is what I found that solved my problem.

When I set up the Web Reference in visual studio I pointed it to the http://sharepointSite/subweb1/subweb2/_vit_bin/lists.asmx as the reference.

However when I went back and checked today it was pointing to http://sharepointSite/_vit_bin/lists.asmx. manually changing it back to http://sharepointSite/subweb1/subweb2/_vit_bin/lists.asmx in the app.config file made all the difference.

@Kit +1 I also added in you suggestion as well. With your suggetion and what I discovered about the web reference, it worked first time.

I ended up just creating a sub web with only 1 field (Title) just to get it working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文