none
Outlook 2010 add-in that creates appointment entries RRS feed

  • Question

  • I have developed an Outlook 2010 add-in that creates appointment entries via C#. Even though I have the newAppointment.Save(); added to the code, when Outlook closes, the user is prompted with a "Do you want to save changes?"

    What do I need to do to stop the user from getting the "Do you want to save changes?" popup message?
    Thursday, March 13, 2014 8:34 PM

All replies

  • Hello niyack,

    What code do you use in the add-in?

    Please make sure that you release all underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the Systematically Releasing Objects article in MSDN.

    Thursday, March 13, 2014 8:56 PM
  • Hi,

    As Eugene mentioned, I suppose there might be some objects not saving or releasing after closing Outlook. It depends on what the code is.

    Here is a sample to create an appointment via C# for your reference:

    How to: Programmatically Create Appointments

    It would be worked for any Outlook add-in project. The little difference is how to define Outlook application.

    You could compare your code with the sample code.

    Hope this helps.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 14, 2014 8:39 AM
    Moderator
  • I have tried both suggestions and I am still getting the Save Prompt.

    Here is part the code that I am using:

    Outlook.Application ouApplication = new Outlook.Application();
                    Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)ouApplication.CreateItem(Outlook.OlItemType.olAppointmentItem);

    <the rest of the appointment code>

    //Save Calendar Entry
                    newAppointment.Save();
                    Marshal.ReleaseComObject(newAppointment);
                    newAppointment = null;

    Tuesday, March 18, 2014 6:33 PM
  • Hello niyack,

    You need to release *all* underlying COM objects, not only the appointment item.

    May we see all your code which works with the Outlook object model?

    Wednesday, March 19, 2014 9:45 AM
  • OK, what else needs to be released?

    Here is the method that I am using to create the calendar entries:

    public static void addAppointmentHRTeC(string[] strPassAppInfo, string strPassStartDate, string strPassEndDate, string strPassStartTime, string strPassEndTime, string strPassStatus)
            {
                DateTime endDate0;
                DateTime endDate1;

                try
                {
                    Outlook.Application ouApplication = new Outlook.Application();
                    Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)ouApplication.CreateItem(Outlook.OlItemType.olAppointmentItem);

                    newAppointment.ReminderSet = true; //Set the reminder
                    newAppointment.ReminderMinutesBeforeStart = 1440; //Reminder time in minutes
                    newAppointment.Importance = Outlook.OlImportance.olImportanceHigh; //Appointment importance
                    newAppointment.BusyStatus = Outlook.OlBusyStatus.olOutOfOffice; //Appointment busy notice
                    newAppointment.Location = strPassAppInfo[0];
                    newAppointment.Subject = strGetRequestSubject;
                    newAppointment.Body = strPassAppInfo[1];

                    if (strPassAppInfo[3].Equals("True"))
                    {
                        //Full Day
                        newAppointment.AllDayEvent = true;
                        endDate0 = Convert.ToDateTime(strPassEndDate);
                        endDate1 = endDate0.AddDays(1);
                    }
                    else
                    {
                        //Partial Day
                        newAppointment.AllDayEvent = false;
                        endDate1 = Convert.ToDateTime(strPassEndDate);
                    }

                    DateTime startDate1 = Convert.ToDateTime(strPassStartDate);
                    DateTime startTime1 = Convert.ToDateTime(strPassStartTime);
                    DateTime endTime1 = Convert.ToDateTime(strPassEndTime);

                    string strGetStartDTF = startDate1.ToString(strCalendarDateFormat) + " " + startTime1.ToString(strCalendarTimeFormatOLNZ);
                    string strGetEndDTF = endDate1.ToString(strCalendarDateFormat) + " " + endTime1.ToString(strCalendarTimeFormatOLNZ);

                    newAppointment.Start = DateTime.Parse(strGetStartDTF);
                    newAppointment.End = DateTime.Parse(strGetEndDTF);
                   
                    //Save Calendar Entry
                    newAppointment.Save();

                    Marshal.ReleaseComObject(newAppointment);
                    newAppointment = null;
                }
                catch (System.Exception ex)
                {
                    string strGetFullErrorMessage = "Add Calendar Entry ERROR: ";
                    MessageBox.Show(strGetFullErrorMessage + ex.Message);
                }
            }

    Wednesday, March 19, 2014 12:20 PM
  • Why do you need to create a new Application instance?

    Instead, you need to use the Application property provided by the VSTO base classes.

    Wednesday, March 19, 2014 1:44 PM
  • I need to create a new Application instance because this code is within the Windows form and for some reason I loose the hook on to the Application property provided by the VSTO base classes.

    Or at least when I tried to use the Application property, it errored out saying that it did not exist


    • Edited by niyack Wednesday, March 19, 2014 6:33 PM
    Wednesday, March 19, 2014 5:20 PM
  • So, why did you choose the VSTO forum if you develop a standalone application?

    It looks like your question is not related to VSTO at all. That's why I'd recommend asking such questions in the General Office Development or Outlook for Developers forums instead.

    Anyway, do you have any add-ins registered for Outlook? They may trigger such message box too.

    Do you use the Quit method of the Application class for closing Outlook?

    Thursday, March 20, 2014 6:41 AM