1

我正在使用下面的代码批量更新共享点列表项,并试图弄清楚我是否也可以使用批量更新来更新项目的内容类型。这适用于 Sharepoint 2010,我只能使用 Web 服务。我无法在任何地方找到一个例子。

public static void UpdateListItems(string SiteURL, string ListName, int[] ItemIDs, List<string> FieldNames, List<object> Values)
    {
        using (ListsSoapClient ls = GetListSoapClient(SiteURL))
        {
            XDocument xDoc = new XDocument(new XElement("Batch"));
            xDoc.Root.Add(new XAttribute("OnError", "Continue"));
            xDoc.Root.Add(new XAttribute("PreCalc", "TRUE"));

            int ID = 0;

            for (int i = 0; i < ItemIDs.Count(); i++)
            {

                ID++;
                XElement xMethod = new XElement("Method",
                    new XAttribute("ID", ID),
                    new XAttribute("Cmd", "Update"),
                    new XElement("Field",
                        new XAttribute("Name", "ID"),
                        ItemIDs[i]
                        )
                    );

                for (int j = 0; j < FieldNames.Count(); j++)
                {
                    xMethod.Add(new XElement("Field",
                                   new XAttribute("Name", Functions.SPFieldName(FieldNames[j])),
                                       Values[j]
                                       )
                               );
                }

                xDoc.Root.Add(xMethod);
            }

            ls.UpdateListItems(ListName, xDoc.Root);
        }
    }
4

3 回答 3

1

如果不制作新版本,就无法使用 SharePoint 2010 的 Web 服务更新内容类型。在 SharePoint 2010 中实现它的唯一方法是使用客户端对象模型。Lists.UpdateListItems 可以做到这一点,但是一旦更新了内容类型,就会添加新的文档版本。

请参阅参考:这些线程

于 2012-05-09T14:41:26.193 回答
0

似乎添加一个名称为“ContentType”的字段并为其赋予内容类型名称的值确实有效。我不知道这是否支持。

于 2012-05-11T13:26:11.117 回答
0

使用内容类型名称,它将在 SharePoint 2010 中工作

<Method ID='1' Cmd='New'><Field Name='Title'>134</Field><Field Name='ContentType'>ContentTypeNameHere</Field></Method>

于 2015-10-13T18:42:26.877 回答