/// <summary> /// Adds an event to the main calendar of the open Outlook Application. /// Utilizes the common methods found in the common library class /// </summary> /// <param name="subject">The subject of the event</param> /// <param name="startDate">The start date of the event in M/d/yyyy hh:mm:ss tt format</param> /// <param name="recurrenceType">What kind of recurrence it is, if one. None, daily, weekly, etc</param> /// <param name="endDate">If there is a recurrence when does the recurrence end.</param> /// <param name="duration">Duration of the event</param> /// <param name="recipients">Who to invite to the event.</param> public void AddEventToMainCalendar(string subject, string startDate, string recurrenceType, string endDate, string duration, string[] recipients) { string methodTag = "AddEventToMainCalendar"; LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG); Outlook.Application app = null; Outlook.AppointmentItem agendaMeeting = null; app = new Outlook.Application(); agendaMeeting = (Outlook.AppointmentItem)app.CreateItem(Outlook.OlItemType.olAppointmentItem); LogWriter.WriteInfo(TAG, methodTag, "Adding details to event item"); try { agendaMeeting = CommonLibrary.CreateEvent(agendaMeeting, subject, startDate, recurrenceType, endDate, duration, recipients); } catch (Exception e) { throw e; } agendaMeeting.Send(); LogWriter.WriteInfo(TAG, methodTag, subject + " created and sent"); return; }
/// <summary> /// Adds an event to another calendar in the outlook application. Calendar must be present in /// the shared folder of outlook. Creates an event object in that folder and then utilizes /// common library to add the attributes /// </summary> /// <param name="subject">Title of the event to add</param> /// <param name="startDate">The date of the specific event M/d/yyyy hh:mm:ss tt</param> /// <param name="recurrenceType">Recurrence type: daily, weekly, monthly, yearly</param> /// <param name="endDate">End date for the recurrence</param> /// <param name="duration">Duration of the event</param> /// <param name="otherCalendar">Name of the other calendar</param> /// <param name="recipients">Array of recipeints to add to the event</param> public void AddEventToOtherCalendar(string subject, string startDate, string recurrenceType, string endDate, string duration, string otherCalendar, string[] recipients) { string methodTag = "AddEventToOtherCalendar"; LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG); Outlook.Application app = null; Outlook.AppointmentItem agendaMeeting = null; Outlook.NameSpace NS = null; Outlook.MAPIFolder objFolder = null; Outlook.MailItem objTemp = null; Outlook.Recipient objRecip = null; Outlook.Items objItems = null; app = new Outlook.Application(); NS = app.GetNamespace("MAPI"); objTemp = app.CreateItem(Outlook.OlItemType.olMailItem); objRecip = objTemp.Recipients.Add(otherCalendar); objTemp = null; objRecip.Resolve(); if (objRecip.Resolved) { objFolder = NS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar); objItems = objFolder.Items; agendaMeeting = objItems.Add(); LogWriter.WriteInfo(TAG, methodTag, "Adding details to event item"); agendaMeeting = CommonLibrary.CreateEvent(agendaMeeting, subject, startDate, recurrenceType, endDate, duration, recipients); LogWriter.WriteInfo(TAG, methodTag, "Sending event"); agendaMeeting.Send(); LogWriter.WriteInfo(TAG, methodTag, subject + " sucessfully sent"); } else { LogWriter.WriteWarning(TAG, methodTag, "Recipient object was not sucessfully resolved"); throw new NullReferenceException(); } return; }