Sharepoint “更新结束日期原因”;无效数据已用于更新列表项“0”;

Sharepoint “更新结束日期原因”;无效数据已用于更新列表项“0”;,sharepoint,sharepoint-2010,Sharepoint,Sharepoint 2010,以下是全部错误: Invalid data has been used to update the list item. The field you are trying to update may be read only. 我基本上是在尝试更新Sharepoint中的日历事件 首先,我得到以下信息 ClientContext clientContext = new ClientContext(deptUrl); Web web = clientContext.Web; List list

以下是全部错误:

Invalid data has been used to update the list item. The field you are trying to update may be read only.
我基本上是在尝试更新Sharepoint中的日历事件

首先,我得到以下信息

ClientContext clientContext = new ClientContext(deptUrl);
Web web = clientContext.Web;
List list = web.Lists.GetByTitle(deptCal);
clientContext.Load(list);

CamlQuery query = new CamlQuery();
query.ViewXml = "<View><Query><Where><IsNull><FieldRef Name='EndDate' /></IsNull></Where></Query><RowLimit>1</RowLimit></View>";

ListItemCollection allEventIds = list.GetItems(query);

clientContext.Load(allEventIds, 
items => items.Include(
     item => item["EventID"],
     item => item["EventDate"],
     item => item["EndDate"]
));

clientContext.ExecuteQuery();
最后:

clientContext.ExecuteQuery();
如果我尝试更新ListItem中的任何其他项[x],则可以正常工作。当我尝试更新“结束日期”时。我得到以下错误:

Microsoft.SharePoint.Client.ServerException was unhandled
  Message="Invalid data has been used to update the list item. The field you are trying to update may be read only."
  Source="Microsoft.SharePoint.Client.Runtime"
  ServerErrorCode=-2147024809
  ServerErrorTypeName="System.ArgumentException"
  ServerStackTrace=""
  StackTrace:
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
       at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
       at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
       at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
       at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
       at DisplayOnCalendarUtility.Program.Main(String[] args) in C:\Projects\DisplayOnCalendarUtility\DisplayOnCalendarUtility\Program.cs:line 61
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Sharepoint是这样连接的。当您自己更新EndDate时,它会给您一个上面列出的错误。解决方案是同时更新EventDate和EndDate

DateTime startDate = DateTime.Parse(objValue.ToString());
item["EventDate"] = startDate;
item["EndDate"] = startDate; //Or Any other date you want to set to.

如果日期不为空,请检查您要传递的日期的格式并确保其正确无误。此外,请检查日期字段是否确实是日期类型而不是字符串。DateTime.Parse(字符串)是否会使其成为有效字符串?此外,我还验证了它不是字符串,因为我尝试保存字符串值。哇…完全出乎意料的解决方案!
DateTime startDate = DateTime.Parse(objValue.ToString());
item["EventDate"] = startDate;
item["EndDate"] = startDate; //Or Any other date you want to set to.