获取交换日历项目的uid

时间:2016-08-01 12:19:47

标签: c# exchangewebservices icalendar ews-managed-api

虽然我已经在视图上设置了属性,但是当我以这种方式编写代码时,我无法检索到它的uid。

    static void GetCalendarItem(ExchangeService svc, string iCalUid)
    {
        var view = new ItemView(500);
        var propSet = new PropertySet(BasePropertySet.IdOnly);
        propSet.Add(ItemSchema.Subject);
        propSet.Add(MeetingMessageSchema.ICalUid);
        var items = svc.FindItems(WellKnownFolderName.Calendar, view);
        foreach (var item in items)
        {
            var subject = item.Subject;
            var guid = DefaultExtendedPropertySet.PublicStrings;
            var epdUid = new ExtendedPropertyDefinition(guid, "UID", MapiPropertyType.Binary);
            string uid = string.Empty;
            var result = false;
            if(item.TryGetProperty<string>(epdUid, out uid))
            {
                result = true; 
            }

            Console.WriteLine("Sub: {0}, Result: {1}", subject, result);
        }
    }

我正在使用托管的ews api 2.2。在此示例中,结果始终打印为false

1 个答案:

答案 0 :(得分:0)

您的代码存在多个问题,您已创建了一个属性集,但尚未在Itemview中设置该属性。您的ExtendedProperty不正确,除非您拥有自己的具有该定义的扩展属性,并且您尚未在任何EWS操作中加载它,因此我将不会显示任何值。您的代码应该看起来像

static void GetCalendarItem(ExchangeService svc, string iCalUid)
{
    var view = new ItemView(500);
    var propSet = new PropertySet(BasePropertySet.IdOnly);
    propSet.Add(ItemSchema.Subject);
    propSet.Add(MeetingMessageSchema.ICalUid);
    view.PropertySet = propSet;
    var items = svc.FindItems(WellKnownFolderName.Calendar, view);
    foreach (var item in items)
    {
        var subject = item.Subject;
        var result = item.ICalUid;


        Console.WriteLine("Sub: {0}, Result: {1}", subject, result);
    }
}