更新事件SharePoint日历C#

时间:2014-06-13 07:46:11

标签: c# sharepoint sharepoint-2010 calendar sharepoint-2013

我可以使用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();
}

1 个答案:

答案 0 :(得分:1)

这不是您应该更新的方式。您应该获取现有项目并进行更新。如果您知道现有项目的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

结帐

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