更新事件SharePoint日历c#

本文关键字:日历 SharePoint 事件 更新 | 更新日期: 2023-09-27 18:08:22

我可以使用C#代码在SharePoint日历上创建事件,但是可以使用C#更新此事件吗?我尝试了这个代码,添加事件作为一个新的,但不能删除旧的使用C#:

SPList list = web.Lists.TryGetList(sCalendarName);
if (list != null)
{
   SPListItem item = list.Items.Add();
   item["Title"] = "New Event";
   item["Description"] = "New Event created using SharePoint Object Model";
   item["Location"] = "First Floor";
   item["EventDate"] = DateTime.Now;
   item["EndDate"] = DateTime.Now.AddDays(2);
   item["Category"] = "Business";
   item["fAllDayEvent"] = false;
   item["Author"] = web.EnsureUser(@"domen'username");
   item.Update();
}

更新事件SharePoint日历c#

不应该这样更新。您应该获取现有项目并更新它。如果您知道现有项目的ID,例如,如果它是34:

SPListItem item = list.GetItemById(34);
   item["Title"] = "New Event";
   item["Description"] = "New Event created using SharePoint Object Model";
   item["Location"] = "First Floor";
   item["EventDate"] = DateTime.Now;
   item["EndDate"] = DateTime.Now.AddDays(2);
   item["Category"] = "Business";
   item["fAllDayEvent"] = false;
   item["Author"] = web.EnsureUser(@"domen'username");
   item.Update();
更新:

查看这里的示例:

http://msdn.microsoft.com/en-us/library/office/ee539976%28v=office.14%29.aspx

Check out

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.getitembyid%28v=office.14%29.aspx