iam using the EWS Managed API 2.0 to create an Appontment. It works fine. But want to Update an existing Appointment, too.
I read that i need the appointment ID to specify which appoint should be edited. But where is the ID?
Here is how i create an Appointment:
'Creates the Appointment
Dim appointment As New EWS.Appointment(esb)
appointment.Subject = txtThema.Text
appointment.Body = txtBemerkung.Text
appointment.Start = Von
appointment.End = Bis
appointment.Location = lbRaumInfo.Text
'Adds the Attendees
For i = 1 To emaillist.Length - 1
appointment.RequiredAttendees.Add(emaillist(i))
Next
'Sending
appointment.Save(EWS.SendInvitationsMode.SendToAllAndSaveCopy)
The temporary unique ID for the AppointmentItem
can be retrieved via the ItemSchema's
Id
property. It should be present after saving the AppointmentItem
.
ItemId id = appointment.Id;
The ItemId
can change if the AppointmentItem
is moved or copied.
A way to do it, is to use the Unique ID as suggested by SilverNinja, and as he said that this is not permanent ID and it can be changed once the appointment is moved to different folder (like if it has been deleted for example).
A way to deal with this problem is to create an extended property, and put guid for the appointment, and it wont change unless you made a copy from another appointment (after all it is just a property)
I have it in C# , but I am sure it is pretty easy to convert to VB
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;
}