简体   繁体   English

更新事件SharePoint日历C#

[英]Update Event SharePoint Calender C#

I can create event on SharePoint calender using C# code , but is it possible to update this event using C# ? 我可以使用C#代码在SharePoint日历上创建事件,但是可以使用C#更新此事件吗? I tried this code, to add the event as a new one but can't delete the old one using 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();
}

This is not how you should update. 这不是应该更新的方式。 You should get the existing item and update it. 您应该获取现有项目并进行更新。 If you know the ID of existing item, for example , if its 34: 如果您知道现有项目的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();

Update: 更新:

Check out the examples here: 在此处查看示例:

http://msdn.microsoft.com/en-us/library/office/ee539976%28v=office.14%29.aspx 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 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.getitembyid%28v=office.14%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM