2016-09-28 22 views
1

我在更新討論項目的SharePoint在線任何屬性時出現此錯誤。在文檔庫和自定義列表的情況下不會發生錯誤。錯誤代碼是-2147024809我的代碼是這樣的。無效數據已用於更新列表項。您嘗試更新的字段可能是隻讀的

public static SBUpdatePropsResponse UpdateProps(string siteCollectionUrl,string webUrl ,SBUpdatePropsRequest updateRequest) 
{ 
    var updateResponse = new SBUpdatePropsResponse(); 
    var clientContext = Admin.GetAuthenticatedClientContext(webUrl); 
    var web = clientContext.Web; 
    var oList = clientContext.Web.Lists.GetById(updateRequest.ListID); 

    var itemProps = updateRequest.ItemProperties; 
    var itemUserProps = updateRequest.UserTypeProperties; 
    var itemDateTimeProps = updateRequest.DateTimeItemProperties; 

    ListItem listItem = oList.GetItemById(updateRequest.DocID); 
    clientContext.Load(web); 
    clientContext.Load(listItem); 
    clientContext.ExecuteQuery();     
    try 
    { 
     //Need to create a extra dictionary to save server time against property     
     var itemDateTimePropsLocal = new Dictionary<string, string>(); 
     foreach (var prop in itemDateTimeProps) 
     { 
      var dateTimeLocal = new DateTime(prop.Value, DateTimeKind.Utc); 
      var temp = web.RegionalSettings.TimeZone.UTCToLocalTime(dateTimeLocal); 
      clientContext.ExecuteQuery(); 
      itemDateTimePropsLocal.Add(prop.Key, temp.Value.ToString()); 
     } 

     foreach (var userProp in itemUserProps) 
     { 
      if (userProp.Value != null && !string.IsNullOrEmpty(userProp.Value.ToString())) 
      { 
       var uservalues = userProp.Value as int[]; 
       //Handle for multi user property 
       if (uservalues.Length > 1) 
       { 
        var propValues = new List<FieldUserValue>(); 
        foreach (var values in uservalues) 
        { 
         if (values > 0) 
          propValues.Add(new FieldUserValue { LookupId = values }); 
        } 
        listItem[userProp.Key] = propValues.ToArray(); 
       } 
       else 
        listItem[userProp.Key] = (new FieldUserValue { LookupId = uservalues[0] }); 
      } 
     }    

     foreach (var prop in itemProps) 
     { 
      if (prop.Key.Equals("ContentType")) 
       continue; 
      if (prop.Value != null && !string.IsNullOrEmpty(prop.Value.ToString()) && prop.Value.GetType() != typeof(FieldUrlValue)) 
       listItem.ParseAndSetFieldValue(prop.Key, prop.Value.ToString()); 
     } 

     foreach (var prop in itemDateTimePropsLocal) 
     { 
      listItem[prop.Key] = prop.Value; 
     } 
     listItem.Update(); 
     clientContext.ExecuteQuery(); 
     updateResponse.IsSuccess = true; 
    } 
    catch(Exception ex) 
    { 
     Logging.LogWriteLine("Failed to update list item properties", ex); 
     updateResponse.IsSuccess = false; 
    } 

}

回答

0

我在這裏把我的答案的情況下,人們通過谷歌搜索的錯誤消息,發現了這個問題,在這太問題的稱號。這個答案可能會幫助其他人遇到這個奇怪的錯誤信息。

我在使用服務器端代碼更新日曆事件時發生同樣的錯誤。

我的代碼首先添加了一個新的空列表項。這個新的列表項具有開始日期和結束日期的默認值。幾行後,列表項字段逐個更新(類似於操作碼),然後調用列表項update。在我的情況下,開始日期沒有被我的代碼更新,並保持默認值。結束日期通過我的代碼進行了更新,並使得結束日期早於開始日期。當調用列表項目update時,此錯誤將顯示在我的例外日誌中。

一旦我糾正這一情況,並將開始日期調整爲始終在結束日期之前下降,然後致電update,錯誤就消失了。

相關問題