sharepoint - 更新 EndDate 导致 "Invalid data has been used to update the list item"

标签 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 = 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();

接着是一个循环:

foreach (var item in allEventIds)
{
   Console.Write("EventId: {0} StartDate: {1}\n", item.FieldValues["EventID"], item.FieldValues["EventDate"]);

                if (item.FieldValues.ContainsKey("EventDate"))
                {
                    object objValue = item.FieldValues["EventDate"];
                    if (objValue != null)
                    {
                        clientContext.Load(item);                        
                        DateTime endDate = DateTime.Parse(objValue.ToString());
                        item["EndDate"] = endDate; //Updated this!

                    }
                }
                item.Update();

            }

然后最后:

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.

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/31e84d74-3ea8-44df-86dc-2dc62381ab3b/#33ad370b-b137-4c2f-bcaa-d6f5c714f4dd

关于sharepoint - 更新 EndDate 导致 "Invalid data has been used to update the list item",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10079961/

相关文章:

.net - 如何从 SharePoint 列表中获取列名称?

c# - 在哪里可以找到 Microsoft.IdentityModel.Extensions.dll 库?

sharepoint - 门户站点地图提供商

javascript - $资源:badcfg when calling sharepoint rest service using angular

powershell - 如何获取网站集或网站或列表的 GUID

sharepoint - 在 SP2010 中部署基于自定义布局的页面

javascript - Sharepoint Web 部件中的外部 Javascript 文件

jquery - SharePoint 2010 功能区隐藏/{在库项目选择或其他事件上显示}

ios - 在 UIWebView 中显示授权提示

sharepoint - 为什么应用步骤在 SharePoint Designer 中显示为灰色