1

C# のクライアント オブジェクト モデルを使用して、Sharepoint ディスカッション ボードのフィールドを更新しようとしています。コードが に到達するclientContext.ExecuteQuery()と、次のように例外がスローされます。

Invalid data has been used to update the list item. The field you are trying to update may be read only.

コードの一部は次のとおりです。

foreach (var field in newItemProperties)
{
    if (field.Key.Equals("ContentType"))
        continue;

    if (ctFields == null)
        spItem[field.Key] = field.Value;

    else
    {
        bool foundField = false;
        foreach (var fieldCT in ctFields)
        {
            fieldCT.ReadOnlyField=false;
            if (fieldCT.InternalName == field.Key)
            {
                foundField = true;
                if (isAllDayEvent)
                {
                    if (field.Key == "EventDate")
                    {
                        // For all day event, Add 10 hour in order to prevent the EventDate to be decreased by 1 day
                        var dateVal = (DateTime)field.Value;
                        // spItem[field.Key] = dateVal.Add(new TimeSpan(0, 10, 0, 0, 0));
                    }
                    else if (field.Key == "EndDate")
                    {
                        // For all day event, Subtract 10 hour in order to prevent the EndDate to be increased by 1 day
                        var dt = (DateTime)field.Value;
                        // spItem[field.Key] = dt.Subtract(new TimeSpan(0, 10, 0, 0, 0));
                    }
                    else
                        spItem[field.Key] = field.Value;

                }
                else
                    spItem[field.Key] = field.Value;

                break;
            }
        }

        if (!foundField)
        {
            // Update the item properties values even its not part of CT
            // MM hidden fields are not part of CT fields
            if (isAllDayEvent)
            {
                if (field.Key == "EventDate")
                {
                    // For all day event, Add 10 hour in order to prevent the EventDate to be decreased by 1 day
                    var dateVal = (DateTime)field.Value;
                    //spItem[field.Key] = dateVal.Add(new TimeSpan(0, 10, 0, 0, 0));
                }
                else if (field.Key == "EndDate")
                {
                    // For all day event, Subtract 10 hour in order to prevent the EndDate to be increased by 1 day
                    var dt = (DateTime)field.Value;
                    //spItem[field.Key] = dt.Subtract(new TimeSpan(0, 10, 0, 0, 0));
                }
                else
                    spItem[field.Key] = field.Value;

            }
            else
                spItem[field.Key] = field.Value;
        }
    }
}

spItem.Update();            
clientContext.ExecuteQuery();
4

2 に答える 2