Пример #1
0
        /// <summary>
        /// Remove a specific event or a series of event from a shared calendar in outlook
        /// Requires the shared calendar to be opened in outlook.
        /// If the eventDate is specificed removes a specific instance. If not removes all events with that subject
        /// </summary>
        /// <param name="subject">Subject of the event to remove</param>
        /// <param name="eventDate">Date of the specific event to remove. If null, deletes all event with the title. M/d/yyyy hh:mm:ss tt</param>
        /// <param name="otherCalendar">Name of the calendar the event exists in</param>
        public void RemoveEventOtherCalendar(string subject, string eventDate, string otherCalendar)
        {
            string methodTag = "RemoveEventOtherCalendar";

            LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG);

            Outlook.Application app       = 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;

            LogWriter.WriteInfo(TAG, methodTag, "Attempting to resolve recipient object for: " + otherCalendar);
            objRecip.Resolve();

            if (objRecip.Resolved)
            {
                objFolder = NS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar);
                objItems  = objFolder.Items;

                LogWriter.WriteInfo(TAG, methodTag, "Attempting to remove: " + subject);
                CommonLibrary.RemoveEvent(objItems, subject, eventDate);
                LogWriter.WriteInfo(TAG, methodTag, subject + " successfully removed");
            }
            else
            {
                LogWriter.WriteWarning(TAG, methodTag, "Recipient object was not sucessfully resolved");
                throw new NullReferenceException();
            }

            return;
        }
Пример #2
0
        /// <summary>
        /// Removes an event or a series of events based on the title
        /// that is currently in the main calendar of the open Outlook Application
        /// If the eventDate is specified it will only remove that specific instance
        /// If it is not specified will remove all events with that title
        /// Utilizes the common methods found in the common library class
        /// </summary>
        /// <param name="subject">Title of the event to remove</param>
        /// <param name="eventDate">The date of the specific event M/d/yyyy hh:mm:ss tt. Not required</param>
        public void RemoveEventMainCalendar(string subject, string eventDate)
        {
            string methodTag = "RemoveEventMainCalendar";

            LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG);

            Outlook.Application app       = null;
            Outlook.Items       objItems  = null;
            Outlook.MAPIFolder  objFolder = null;

            app = new Outlook.Application();
            Outlook.NameSpace NS = app.GetNamespace("MAPI");

            objFolder = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
            objItems  = objFolder.Items;

            LogWriter.WriteInfo(TAG, methodTag, "Attempting to remove: " + subject);
            CommonLibrary.RemoveEvent(objItems, subject, eventDate);
            LogWriter.WriteInfo(TAG, methodTag, subject + " successfully removed");

            return;
        }