如何使用客户端对象模型创建共享点日历列表项
我正在尝试使用客户端对象模型创建共享点日历事件。我可以创建项目并设置除“EndDate”列之外的所有列的列值。当我尝试设置此列时,出现以下错误:德语消息翻译为“更新列表条目时使用了无效数据。您要更新的字段可能受到写保护”。如果跳过此列,则列出在 Sharepoint 服务器上创建的不带 enddate 属性的项目,但在日历视图中不可见。我可以在“datasheetview”类型的视图上看到项目,如果我从这里设置结束日期,它在日历视图中也可见。(奇怪的是它是必填字段)
Server Exception Microsoft.SharePoint.Client.ServerException was unhandled. Message=Es wurden ungültige Daten zur Aktualisierung des Listeneintrags verwendet. Das Feld, das Sie aktualisieren möchten, ist möglicherweise schreibgeschützt. 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 Sp_Ctx.Program.Main(String[] args) in_Ctx\Program.cs:line 129 InnerException:
我的代码如下
using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite)){ if (ctx != null) {
ctx.Load(ctx.Web); // Query for Web
ctx.ExecuteQuery(); // Execute
Console.WriteLine(ctx.Web.Title);
List list = ctx.Web.Lists.GetByTitle("calendarListName");
ctx.Load(list.Fields);
ctx.ExecuteQuery();
var newItem = list.AddItem(listItemCreationInfo);
newItem.Update();
newItem["Title"] = "myCalendar" .....
newItem["EventDate"]= DateTime.Now;
newItem["EndDate"]= DateTime.Now.AddMinutes(30);
newItem["Location"]= "Office";
newItem.Update();
ctx.ExecuteQuery();
}
I am trying to create a sharepoint calendar event using client object model. I can create item and set column values all columns except "EndDate" column. When I try to set this column I get the following error Translation of message from German is "Invalid data is used while updating list entry. The field you want to update is possibly write protected." If skip this column, list item created at Sharepoint server without enddate property, but it is not visible at calendar view. I can see item on "datasheetview" type of view, and if I set the enddate from here it is also visible at calendar view.(strange thing is it is mandatory field)
Server Exception Microsoft.SharePoint.Client.ServerException was unhandled. Message=Es wurden ungültige Daten zur Aktualisierung des Listeneintrags verwendet. Das Feld, das Sie aktualisieren möchten, ist möglicherweise schreibgeschützt. 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 Sp_Ctx.Program.Main(String[] args) in_Ctx\Program.cs:line 129 InnerException:
my code is as follows
using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite)){ if (ctx != null) {
ctx.Load(ctx.Web); // Query for Web
ctx.ExecuteQuery(); // Execute
Console.WriteLine(ctx.Web.Title);
List list = ctx.Web.Lists.GetByTitle("calendarListName");
ctx.Load(list.Fields);
ctx.ExecuteQuery();
var newItem = list.AddItem(listItemCreationInfo);
newItem.Update();
newItem["Title"] = "myCalendar" .....
newItem["EventDate"]= DateTime.Now;
newItem["EndDate"]= DateTime.Now.AddMinutes(30);
newItem["Location"]= "Office";
newItem.Update();
ctx.ExecuteQuery();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案很简单,一起更新事件日期和结束日期。原始解决方案是可以在这里看到
Answer was simple update the eventdate and the enddate together. Original solution is can be seen here