Pergunta

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.

Foi útil?

Solução

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
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top