以下是完整的錯誤:更新結束日期將導致「無效數據已被用於更新列表項」
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();
如果我嘗試更新任何其他項目[X]在列表項工作正常。當我嘗試更新「EndDate」時。我收到以下錯誤:
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:
如果日期不爲空,請檢查您傳遞的日期格式,並確保它是正確的。另外,檢查日期字段是否真的是日期類型而不是字符串。 – NoChance 2012-04-09 21:23:16
不會DateTime.Parse(字符串)使它成爲一個有效的字符串?另外,我已經驗證它不是一個字符串,因爲我嘗試保存一個字符串值。 – jmogera 2012-04-10 13:05:58