如何使用客户端对象模型创建共享点日历​​列表项

发布于 2024-12-29 01:41:02 字数 2041 浏览 1 评论 0原文

我正在尝试使用客户端对象模型创建共享点日历​​事件。我可以创建项目并设置除“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷炫老祖宗 2025-01-05 01:41:02

答案很简单,一起更新事件日期和结束日期。原始解决方案是可以在这里看到

Answer was simple update the eventdate and the enddate together. Original solution is can be seen here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文