2

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

}
LiveKarma
  • 221
  • 2
  • 13

1 Answers1

2

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...
    }
Oren Chapo
  • 519
  • 7
  • 15
  • I have just found this online also, so far I have been able to save them using something just like your example however I am now struggling to read property from the appointment. See my original post edit :) – LiveKarma Jul 02 '14 at 12:19
  • I've used custom properties with the specific Guid "{00020329-0000-0000-C000-000000000046}" successfully, both write and read. According to [KB907985](http://support.microsoft.com/kb/907985): "Outlook custom fields, or properties, that you use on an Outlook custom form all have the GUID {00020329-0000-0000-C000-000000000046}. In MAPI, the GUID is referred to as PS_PULIC_STRINGS. However, custom MAPI programs may have their own GUIDs for custom properties." – Oren Chapo Jul 02 '14 at 12:33
  • I've just reviewed old code and found out you need to specify your property set when binding the appointment item. See my updated answer :-) – Oren Chapo Jul 02 '14 at 12:49
  • Thats perfect thank you, I will give that a go and give you the answer mark if it works :) – LiveKarma Jul 02 '14 at 13:42