EWS Create Appointment in exchange with extra custom properties

江枫思渺然 提交于 2019-12-01 09:08:29

问题


Im currently looking at a way to save a few extra properties to an exchange appointment using C#. Currently I can save using the following properties:

Appointment calendar = new Appointment(p_service);

calendar.Subject = calendarS5Subject;
calendar.Body = calendarS5Body;
calendar.Start = calendarS5StartDateTime;
calendar.End = calendarS5EndDateTime;
calendar.IsReminderSet = false;
calendar.Location = calendarS5Location;
calendar.Body.BodyType = BodyType.Text;

calendar.Save();

However I want to be able to store my own custom properties like calendar.EventID and calendar.Blah . Is it possible to save these properties against the appointment and then be able to access them later? It would be even better if it could all be stored as a user control form inside the appoint window. I know you can do this with an outlook addin that uses the type AppointmentItem. However I am yet to find a way to do it with exchange with the type of Appointment.

TIA.

I have now been able to save the extra property using:

Guid EventIDSetGUID = new Guid("{C11FF724-AA03-4555-9952-8FA248A11C3E}");
ExtendedPropertyDefinition extendedPropertyEventID = new ExtendedPropertyDefinition(EventIDSetGUID, "EventID", MapiPropertyType.String);
calendar.SetExtendedProperty(extendedPropertyEventID, calendarS5EventID);

However I am now struggling to read back that property later on. This work right after I have saved the extra property but if I restart the application and then try to read the extra property eventIDProp always returns null. My code for reading:

Guid EventIDReadGUID = new Guid("{C11FF724-AA03-4555-9952-8FA248A11C3E}");
ExtendedPropertyDefinition extendedPropertyEventIDRead = new ExtendedPropertyDefinition(EventIDReadGUID, "EventID", MapiPropertyType.String);
object eventIDProp;
if (calendar.TryGetProperty(extendedPropertyEventIDRead, out eventIDProp) && eventIDProp != calendarS5EventID)
{

}

回答1:


You can do that with MAPI extended properties:

    // Define MAPI extended properties
    private readonly ExtendedPropertyDefinition _extendedPropEventId = 
        new ExtendedPropertyDefinition(
            new Guid("{00020329-0000-0000-C000-000000000046}"),
            "Event Identifier",
            MapiPropertyType.String);

    private readonly ExtendedPropertyDefinition _extendedPropBlah = 
        new ExtendedPropertyDefinition(
            new Guid("{00020329-0000-0000-C000-000000000046}"),
            "Blah",
            MapiPropertyType.String);

...

    // Set extended properties for appointment
    calendar.SetExtendedProperty(_extendedPropEventId, "custom EventID value");
    calendar.SetExtendedProperty(_extendedPropBlah, "custom Blah value");

...

    // Bind to existing item for reading extended properties
    var propertySet = new PropertySet(BasePropertySet.FirstClassProperties, _extendedPropEventId, _extendedPropBlah);
    var calendar = Appointment.Bind(p_service, itemId, propertySet);
    if (calendar.ExtendedProperties.Any(ep => ep.PropertyDefinition.PropertySetId == _extendedPropEventId.PropertySetId))
    {
        // Add your code here...
    }


来源:https://stackoverflow.com/questions/24526704/ews-create-appointment-in-exchange-with-extra-custom-properties

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