0

我在某个字段中添加了我的 SharePoint 解决方案,但我不断收到错误消息the object has been updated by another user since it was last fetched.

foreach (var field in new PageAndFieldData().Fields)
{

    var spField = web.Fields.FirstOrDefault(i => i.InternalName == field.field_name); // if dont exist = create

    if (spField == null)
    {
        var fieldXml = field.Xml;
        var newspField = web.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.DefaultValue);
        if (groups.Contains(field.group_name))
            newspField.Group = field.group_name;
        else
        {
            newspField.Group = field.group_name;
        }
        _Ctx.Load(newspField);
        _Ctx.ExecuteQuery(); <--- This line throws the error
    }
}

有人可以指出为什么它不断抛出错误。

4

2 回答 2

3

确保字段架构(fieldXml在您的情况下为变量)不包含Version属性,否则 SharePoint 会认为该字段正在更新。

例如,使用以下字段架构创建字段时会发生错误:

<Field Version='1' Type='Geolocation' DisplayName='Location' /> 

并且不会:

<Field Type='Geolocation' DisplayName='Location' />
于 2017-01-18T13:50:51.717 回答
0

可能有一个与该列表关联的工作流,它会被触发并与您的代码同时修改项目。

如果没有工作流,则该项目可能被其他用户修改,就像它说的那样。关键是,从您获取它到您在 SharePoint 中更新它的时间,不应在 SP 中修改该项目(由其他人),否则 SP 会出现“冲突更改”错误。

于 2017-01-18T12:40:40.100 回答