无法更新“全天活动”和“EndDate”使用C#代码/ Powershell从日历列表中 [英] Not able to update "All Day Event" and "EndDate" from Calendar list using C# code/Powershell
问题描述
大家好,
我有一个日历列表,我的要求是更新"EndDate"。和"fAllDayEvent"现有项目的列数据。
I have a Calendar list and my requirement is to update "EndDate" and "fAllDayEvent" columns data for existing items.
在更新现有项目时,我的两列都低于错误。
While updating existing items i am getting below error for both the columns.
"无效数据已被用于更新列表项。您尝试更新的字段可能只读。"
"Invalid data has been used to update the list item. The field you are trying to update may be read only."
我尝试过使用CSOM代码和Powershell。
I have tried using CSOM Code and Powershell both.
环境 - Office 365
Environment- Office 365
提前致谢
Sunita
推荐答案
< span style ="color:#1F497D">我们需要一起更新EventDate和EndDate,因为AllDayEvent会引用其他两个字段。
<d:SchemaXml><Field ID="{7d95d1f4-f5fd-4a70-90cd-b35abc9b5bc8}" Type="AllDayEvent" Name="fAllDayEvent" DisplaceOnUpgrade="TRUE" DisplayName=" AllDayEvent" Sealed="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="fAllDayEvent" ColName="bit1"><FieldRefs><FieldRef Name="EventDate" RefType="StartDate" /><FieldRef Name="EndDate" RefType="EndDate" /><FieldRef Name="TimeZone" RefType="TimeZone" /><FieldRef Name="XMLTZone" RefType="XMLTZone" /></FieldRefs></Field></d:SchemaXml>
示例测试代码。
string siteUrl = "https://tenant.sharepoint.com/sites/developer";
string userName = "lee@tenant.onmicrosoft.com";
string password = "pw";
using (var ctx = new ClientContext(siteUrl))
{
SecureString securePassword = new SecureString();
foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);
#region update events
List oList = ctx.Web.Lists.GetByTitle("myCalendar");
var item = oList.GetItemById(5);
item["EventDate"] = DateTime.Now;
item["EndDate"] = DateTime.Now.AddDays(3);
item["fAllDayEvent"] = true;
item.Update();
ctx.ExecuteQuery();
#endregion
}
最好的问候,
< span style ="font-size:10.0pt; line-height:105%; font-family:'Arial',sans-serif;颜色:#2F5597"> Lee
这篇关于无法更新“全天活动”和“EndDate”使用C#代码/ Powershell从日历列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!