Bind custom extended property for existing appointment using EWS managed API 2.0

醉酒当歌 提交于 2019-12-31 03:26:11

问题


I want to make unique appointment to put in database using custom extended properties. I find all appointments using FindAppointments():

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

and than i go trough all appointments using foreach loop:

foreach (var appointment in appointments)

for all appointments which doesn't have extended property:

if (appointment.ExtendedProperties.Count <= 0)

i bind a custom extended property and setting its value with unique meeting id (meetingId) which i specialy generated to be uniqe int number:

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

but it doesn't work because than i search meetings and try output extended property and tis value i dont get results, its not binded. My question what i'm doing wrong and what other soliutions you could offer to give EXISTING appointments custom extended property? By the way, im working with MS Exchange server 2010_SP2.


回答1:


see my answer at this post: Exchange Webservice Managed API - Find items by extended properties I think your problems are pretty simular to this. The "FindItems" methods doesnt load any custom property. thats the reason why

if (appointment.ExtendedProperties.Count <= 0)

is always true, even if the appointment already has your custom property. Next Thing is, that i recommend you to create your Extended property in the DefaultExtendedPropertySet.PublicStrings instead of creating an own guid. I tried own guids as well and never got it working correct.

Try it like this:

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

so finally your code should look like this:

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
    }
}


来源:https://stackoverflow.com/questions/17641738/bind-custom-extended-property-for-existing-appointment-using-ews-managed-api-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!