【问题标题】:Sharepoint calendar event attendeesSharepoint 日历活动参与者
【发布时间】:2014-06-13 15:31:14
【问题描述】:

我想以编程方式将事件添加到 SharePoint 2010 中的日历。我获取事件列表并将元素添加到此列表。

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();
}

但我找不到如何向“参与者”(“与会者”)字段添加值。 如果你看一下 item.Xml,就会看到由 Sharepoint Calendar 界面添加的 ows_ParticipantsPicker 元素,其中包含用户。

如何将参与者(参加者)添加到活动中?

【问题讨论】:

    标签: c# sharepoint sharepoint-2010 calendar


    【解决方案1】:

    您是否尝试过使用 SPFieldUserValueCollection 作为字段的值?

    SPFieldUserValueCollection values = new SPFieldUserValueCollection();
    SPUser user = web.EnsureUser(@"domen\username");
    values.Add(new SPFieldUserValue(web, user.ID, user.Name));      
    item["Participants"] = values;
    

    另外,不要使用 SPList.Items.Add(),它会在添加新项目之前获取所有项目。使用 SPList.AddItem()。

    【讨论】:

    • 好的,我明白了。谢谢!
    猜你喜欢
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    相关资源
    最近更新 更多