Exchange web services: why is ItemId not constant? [continued]
Asked Answered
U

1

9

as some others have discuss this problem before (e.g., Exchange web services: why is ItemId not constant?), I want to talk about the solution, I have done what people have suggested by stamping the Guid as an extended property, For me this solution is kind of nice (although I do not know how to make it work with the occurrences) but only as long as the application works, once the application restarts the extended properties of the items disappear, so my problem now, is “How to stamp the extended property on the EWS item and make it constantly there?” This is the code of updating the calendar items (appointments)

public void SetGuidForAppointement(Appointment appointment)
{         
appointment.SetExtendedProperty((ExtendedPropertyDefinition)_appointementIdPropertyDefinition, Guid.NewGuid().ToString());
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
}

And these are the properties definition needed above.

_appointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, "AppointmentID", MapiPropertyType.String);
            _propertyDefinitionBases = new PropertyDefinitionBase[] { _appointementIdPropertyDefinition, ItemSchema.ParentFolderId, AppointmentSchema.Start, AppointmentSchema.End, 
AppointmentSchema.LegacyFreeBusyStatus, AppointmentSchema.Organizer };
            PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, _propertyDefinitionBases);

So if anyone has done this before could he/she provide me with an example that keeps the extended property stamped on the item even if the application exited. Thanks

Uranian answered 6/8, 2012 at 11:12 Comment(4)
Hello, what exactly do you mean with "once the application restarts the extended properties of the items disappear"?Remontant
I have answered my own question in the answer below :)Uranian
I know. :) But I use extended properties as well, and am curious if it is possible, that the value I store in it is lost at some point?Remontant
I do not thinks so. at least I did not encounter this anymore.Uranian
U
10

I have found the solution to my problem after sometime of trying and searching .

private static readonly PropertyDefinitionBase AppointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "AppointmentID", MapiPropertyType.String);
public static PropertySet PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointementIdPropertyDefinition);


//Setting the property for the appointment 
 public static void SetGuidForAppointement(Appointment appointment)
{
    try
    {
        appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, Guid.NewGuid().ToString());
        appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
    }
    catch (Exception ex)
    {
        // logging the exception
    }
}

//Getting the property for the appointment
 public static string GetGuidForAppointement(Appointment appointment)
{
    var result = "";
    try
    {
        appointment.Load(PropertySet);
        foreach (var extendedProperty in appointment.ExtendedProperties)
        {
            if (extendedProperty.PropertyDefinition.Name == "AppointmentID")
            {
                result = extendedProperty.Value.ToString();
            }
        }
    }
    catch (Exception ex)
    {
     // logging the exception
    }
    return result;
} 
Uranian answered 23/4, 2013 at 15:42 Comment(1)
Ported this to VB to use there. Used as: Dim guid As String = GetGuidForAppointment(appointment) If String.IsNullOrEmpty(guid) Then SetGuidForAppointment(appointment) guid = GetGuidForAppointment(appointment) End IfIndiscrete

© 2022 - 2024 — McMap. All rights reserved.