Lets take them one by one:
Creating Appointments:
AppointmentItem newAppointment;
newAppointment = Application.CreateItem(OlItemType.olAppointmentItem);
newAppointment.MeetingStatus = OlMeetingStatus.olNonMeeting;
newAppointment.Subject = "Dummy";
newAppointment.Location = "Anywhere";
newAppointment.Body = "Hello Appointment";
newAppointment.Start = DateTime.Now;
newAppointment.End = DateTime.Now;
Recipients sentTo = newAppointment.Recipients;
Recipient sentInvite = null;
sentInvite = sentTo.Add(AttendeeAlias);
sentInvite.Type =OlMeetingRecipientType.olRequired;
newAppointment.Display(true);
sentTo.ResolveAll();
newAppointment.Send();
newAppointment.Save();
newAppointment.Close(OlInspectorClose.olDiscard);
If you are using a custom form region and have replaced the default appointment form, you need to add in the corresponding message class:
newAppointment.MessageClass = "IPM.Appointment.Custom_appointment";
Send Cancellation and Deleting
If you are having a handle to the corresponding appointment, use this simple piece of code:
newAppointment.MeetingStatus = OlMeetingStatus.olMeetingCanceled; newAppointment.Send();
newAppointment.Delete();
Searching Calendar for appointments/ Sorting appointments
Get a handle to the folder and use a similar code block:
Folder oCalendar;
Items oItems;
Items oResItems;
String strRestriction;
//Date Formatmm/dd/yyyy hh:mm AMPM
oCalendar=(Folder)Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
oItems = oCalendar.Items;
strRestriction = "[Start] <= '" + startDate.ToLongDateString() + "' AND [End] >= '" + endTime.ToLongDateString() + "'";
oResItems = oItems.Restrict(strRestriction);
oResItems.Sort("[Start]",missing );
Adding custom properties
Use a similar code block. Ideally this should be passed through an encryption routine:
UserProperty transactionID = newAppointment.UserProperties.Add("TransactionID", OlUserPropertyType.olText, true, OlUserPropertyType.olText);
transactionID.Value = "1";
Looking up for custom properties
UserProperty transactionID =existingAppointment.UserProperties.Find("TransactionID", missing);
Handling Appointment Response
The response comes in as a meeting item. Get the associated appointment and loop through the recipient collect to fetch individual response:
MeetingItem mi;
AppointmentItem ai;
ai = mi.GetAssociatedAppointment(false);
ai.Write += new ItemEvents_10_WriteEventHandler(ai_Write);
void ai_Write(ref bool Cancel)
{
Recipients rcps = mi.GetAssociatedAppointment(false).Recipients;
Recipient rp = rcps[Application.Session.CurrentUser.Name]; //Loop across the collection or use a specific alias
string response = rp.MeetingResponseStatus.ToString();
}
Handling Scheduling Assistant Events
The assistant (page control) is a COM control and throws up a single top level event that you can trap in from your addin. This becomes vey handy for custom validation rules.
newAppointment.PropertyChange += new ItemEvents_10_PropertyChangeEventHandler(newAppointment_PropertyChange);
void newAppointment_PropertyChange(string Name)
switch (Name)
case "Start":
UpdateMeetingTimes();
break;
case "End":
case "RequiredAttendees":
UpdateAttendees();
case "OptionalAttendees":
case "ResponseStatus":
UpdateStatus();
case "MeetingStatus":
default: