c# - 使用 EWS 托管 API 2.0 为现有约会绑定(bind)自定义扩展属性

标签 c# exchange-server exchangewebservices ews-managed-api

我想使用自定义扩展属性进行唯一的预约以放入数据库。我使用 FindAppointments() 查找所有约会:

var appointments = _service.FindAppointments(WellKnownFolderName.Calendar, calendarView);

然后我使用 foreach 循环遍历所有约会:

foreach (var appointment in appointments)

对于所有没有扩展属性的约会:

if (appointment.ExtendedProperties.Count <= 0)

我绑定(bind)了一个自定义扩展属性,并使用我专门生成的唯一 session ID (meetingId) 设置其值:

var myPropertySetId = new Guid("{6C3A094F-C2AB-4D1B-BF3E-80D39BC79BD3}");
var extendedPropertyDefinition = new ExtendedPropertyDefinition(myPropertySetId, "RateTheMeetingId", MapiPropertyType.Integer);
var bindedAppointment = Appointment.Bind(_service, appointment.Id, new PropertySet(extendedPropertyDefinition));
bindedAppointment.SetExtendedProperty(extendedPropertyDefinition, meetingId);
bindedAppointment.Update(ConflictResolutionMode.AlwaysOverwrite);

但它不起作用,因为我搜索 session 并尝试输出扩展属性和 tis 值,但我没有得到结果,它没有绑定(bind)。我的问题是我做错了什么以及您可以提供哪些其他解决方案来为现有约会提供自定义扩展属性?顺便说一句,我正在使用 MS Exchange server 2010_SP2。

最佳答案

请参阅我在这篇文章中的回答: Exchange Webservice Managed API - Find items by extended properties 我认为你的问题与此非常相似。 “FindItems”方法不会加载任何自定义属性。这就是原因

if (appointment.ExtendedProperties.Count <= 0)

始终为 true,即使约会已经具有您的自定义属性。接下来,我建议您在 DefaultExtendedPropertySet.PublicStrings 中创建扩展属性,而不是创建自己的 guid。我也尝试过自己的指南,但从未使其正常工作。

尝试这样:

ExtendedPropertyDefinition def = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "RateTheMeetingId", MapiPropertyType.Integer);

所以最后你的代码应该如下所示:

var appointments = _service.FindAppointments(WellKnownFolderName.Calendar, calendarView);

ExtendedPropertyDefinition def = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "RateTheMeetingId", MapiPropertyType.Integer);

PropertySet propset = new PropertySet(PropertySet.IdOnly);
propset.Add(def);

foreach (var appointment in appointments)
{
    //appointment should already be binded, now load it
    appointment.Load(propset);
    object value = null;
    if (item.TryGetProperty(def, out value))
    {
        //Do something
    }
    else
    {
        //Add Property
    }
}

关于c# - 使用 EWS 托管 API 2.0 为现有约会绑定(bind)自定义扩展属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17641738/

相关文章:

c# - .net core 2.0 ConfigureLogging xunit测试

c# - 接收对 UDP 广播的应答 (C#)

c# - 用一个参数解构不起作用

email - 从 Grails 应用程序获取 Exchange 邮件

c# - 在 View 中找不到命名空间,在 Controller 中工作

php - 如何从 PHP 连接到 Exchange 在线 API

c# - 安全使用 'HttpContext.Current.Cache'

c# - 从代码发送电子邮件时出现“5.7.1 Client does not have permission”错误

php - 加载类 EWSType_FindItemType (php-ews) 时出现 fatal error

java - 使用 MS Exchange 服务器从 java 发送邮件,导致连接超时