none
Outlook 2010 Appointment created by Addin Not showing text - sometimes RRS feed

  • Question

  • Hi All,

    I'm attempting to create an add-in for our company that modifies the body text based on selections.  I'm running into an issue where the text isn't sent all of the time.

    My code is as follows (bodyText is a string that is dynamically generated based on other selections in the form):

                Outlook.AppointmentItem newAppointment;
                newAppointment = (Outlook.AppointmentItem)OutlookItem;
                string firstname = "";
                string lastname = "";
             
                 //   Outlook.Account acc = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts[0];
                    firstname = ((dynamic)Globals.ThisAddIn.Application.ActiveExplorer().Session).CurrentUser.Name;
                    if (firstname.Contains(' '))
                    {
                        lastname = firstname.Split(' ')[1];
                        firstname  = firstname.Split(' ')[0];
                    }
                string bodyText = ""; // this is a dynamically formatted string.
                newAppointment.RTFBody = Encoding.ASCII.GetBytes(bodyText);
                newAppointment.Save();
                newAppointment.Close(Outlook.OlInspectorClose.olSave);
                //send to all attendees
                newAppointment.ForceUpdateToAllAttendees = true;
                newAppointment.Send();

    Does anyone see any issues with the above?

    My symptoms are:

       User sometimes doesn't see the text when creating a meeting (what is the difference between a meeting and appointment and how do I handle that?)

       This works fine on a Windows XP SP 3 or Windows 7 32 bit machine . . . as soon as we go to x64 on Windows 7 the text won't populate unless the appointment already exists.  (EG: create a blank appointment, save it, then do this, works fine.)

    Any suggestions greatly appreciated, thanks in advance.

    Thursday, December 12, 2013 5:41 PM

Answers

  • Hi,

    >> What is the difference between a meeting and appointment and how do I handle that? <<

    Appointments are activities that you schedule in your calendar that do not involve inviting other people or reserving resources.

    A meeting is an appointment you invite people to or reserve resources for.

    In Outlook UI, if you involve other people in current appointment, it is a meeting.

    You can find the window title will become “Meeting” after involving other people into this appointment.

    For more information, please refer to About appointments, meetings, and events

    In Outlook, a meeting request is an AppointmentItem. To set an appointment item as a meeting request, you must set the MeetingStatus property to olMeeting:

    newAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;

    Here is the sample I changed according to yours:

    private void SendAppointment()
            {
                Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
                string firstname = "";
                string lastname = "";
    
                //   Outlook.Account acc = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts[0];
                firstname = ((dynamic)Globals.ThisAddIn.Application.ActiveExplorer().Session).CurrentUser.Name;
                if (firstname.Contains(' '))
                {
                    lastname = firstname.Split(' ')[1];
                    firstname = firstname.Split(' ')[0];
                }
                string bodyText = "Test in Outlook 2013"; // this is a dynamically formatted string.
                newAppointment.RTFBody = Encoding.ASCII.GetBytes(bodyText);
                newAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
                newAppointment.Subject = "Subject";
                newAppointment.Location = "Meeting Room B";
                newAppointment.Recipients.Add("xxx@microsoft.com");
                newAppointment.Save();
                newAppointment.Close(Outlook.OlInspectorClose.olSave);
                //send to all attendees
                newAppointment.ForceUpdateToAllAttendees = true;
                newAppointment.Send();
            }
    

    It works fine for me in Outlook 2013 and Windows 8 64-bit.

    >> As soon as we go to x64 on Windows 7 the text won't populate unless the appointment already exists. <<

    The code you provided doesn’t work for me since I don’t know what is “OutlookItem”, so I changed the code as follows:

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

    It will create a new appointment.

    To set text for an appointment, AppointmentItem.RTFBody represents the body of the Microsoft Outlook item in Rich Text Format. I suggest you checking whether the new appointment created correctly and the bodytext.

    If you are still facing the same issue, what’s Office version? would you mind sharing the whole code for us to reproduce this issue?


    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, December 13, 2013 10:41 AM
    Moderator

All replies

  • Hi,

    >> What is the difference between a meeting and appointment and how do I handle that? <<

    Appointments are activities that you schedule in your calendar that do not involve inviting other people or reserving resources.

    A meeting is an appointment you invite people to or reserve resources for.

    In Outlook UI, if you involve other people in current appointment, it is a meeting.

    You can find the window title will become “Meeting” after involving other people into this appointment.

    For more information, please refer to About appointments, meetings, and events

    In Outlook, a meeting request is an AppointmentItem. To set an appointment item as a meeting request, you must set the MeetingStatus property to olMeeting:

    newAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;

    Here is the sample I changed according to yours:

    private void SendAppointment()
            {
                Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
                string firstname = "";
                string lastname = "";
    
                //   Outlook.Account acc = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts[0];
                firstname = ((dynamic)Globals.ThisAddIn.Application.ActiveExplorer().Session).CurrentUser.Name;
                if (firstname.Contains(' '))
                {
                    lastname = firstname.Split(' ')[1];
                    firstname = firstname.Split(' ')[0];
                }
                string bodyText = "Test in Outlook 2013"; // this is a dynamically formatted string.
                newAppointment.RTFBody = Encoding.ASCII.GetBytes(bodyText);
                newAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
                newAppointment.Subject = "Subject";
                newAppointment.Location = "Meeting Room B";
                newAppointment.Recipients.Add("xxx@microsoft.com");
                newAppointment.Save();
                newAppointment.Close(Outlook.OlInspectorClose.olSave);
                //send to all attendees
                newAppointment.ForceUpdateToAllAttendees = true;
                newAppointment.Send();
            }
    

    It works fine for me in Outlook 2013 and Windows 8 64-bit.

    >> As soon as we go to x64 on Windows 7 the text won't populate unless the appointment already exists. <<

    The code you provided doesn’t work for me since I don’t know what is “OutlookItem”, so I changed the code as follows:

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

    It will create a new appointment.

    To set text for an appointment, AppointmentItem.RTFBody represents the body of the Microsoft Outlook item in Rich Text Format. I suggest you checking whether the new appointment created correctly and the bodytext.

    If you are still facing the same issue, what’s Office version? would you mind sharing the whole code for us to reproduce this issue?


    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, December 13, 2013 10:41 AM
    Moderator
  • Hi George,

    Thanks VERY much for the clear explanations. 

    The plugin was created as a seperate FormRegion that displays in appointments.  The OutlookItem is set during the initalizing stage:

            static object OutlookItem;
            #region Form Region Factory
            [Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Appointment)]
            [Microsoft.Office.Tools.Outlook.FormRegionName("My Region Name")]
            public partial class PluginFactory
            {
                // Occurs before the form region is initialized.
                // To prevent the form region from appearing, set e.Cancel to true.
                // Use e.OutlookItem to get a reference to the current Outlook item.
                private void PluginFacotry_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
                {
                    OutlookItem = e.OutlookItem;
                }
            }
            #endregion

    I have a bunch of application logic for storing / editing the fields that I need to dynamically insert . . . I know that part is working correctly as I can save and load the items into the form without issue.  I'll need to get approval to share the entire RTF body as there's company specific information in there; but in the meantime I've gone ahead and set the status to a meeting as well.  I may be a bit slow in respsonses as I'm in training next week and we have the holidays coming up, but wanted to let you know in advanced as I'm very interested in getting this resolved.

    Can you confirm that regardless of a Meeting, Appointment, or Event they all use the Outlook.AppointmentItem class in the code behind?  Also would there be any reason why this wouldn't work on a new Meeting (eg: user created for the first time) but it does work on an existing meeting?

    Thanks again.


    • Edited by Ged325 Friday, December 13, 2013 5:30 PM
    Friday, December 13, 2013 5:26 PM
  • Hi,

    I made a new test for you. I added a button to send the meeting.

    Here is the code in FormRegion.cs:

    private void SendAppointment()
            {
                Outlook.AppointmentItem newAppointment = OutlookItem;
                string firstname = "";
                string lastname = "";
    
                //   Outlook.Account acc = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts[0];
                firstname = ((dynamic)Globals.ThisAddIn.Application.ActiveExplorer().Session).CurrentUser.Name;
                if (firstname.Contains(' '))
                {
                    lastname = firstname.Split(' ')[1];
                    firstname = firstname.Split(' ')[0];
                }
                string bodyText = "Test in Outlook 2013"; // this is a dynamically formatted string.
                newAppointment.RTFBody = Encoding.ASCII.GetBytes(bodyText);
                newAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
                newAppointment.Subject = "Subject";
                newAppointment.Location = "Meeting Room C";
                newAppointment.Recipients.Add("xxx@microsoft.com");
                newAppointment.Save();
                newAppointment.Close(Outlook.OlInspectorClose.olSave);
                //send to all attendees
                newAppointment.ForceUpdateToAllAttendees = true;
                newAppointment.Send();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                SendAppointment();
            }

    OutlookItem defined as you provided.

    The code worked fine both on a new meeting and an existing meeting.

    Since I can't reproduce this issue, so I can't explain why the issue happened.

    You could copy my code to check whether the issue was still existing. Also, you could debug the code while creating a new meeting to check whether the appointment object was a meeting. 


    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.

    Monday, December 16, 2013 10:19 AM
    Moderator
  • Hi George,

    The person that this is happening for travels a lot, but I was finally able to gain access to the PC.  I've verified that the issue does happen on HIS laptop . . . I have another 64 bit machine where this is working fine. 

    It's worth noting that if I click the save button for the appointment in the upper left hand corner, and then I click the button to create the meeting the text shows up as expected.

            static object OutlookItem;
            [Microsoft.Office.Tools.Outlook.FormRegionName("MyFormRegion")]
            public partial class MyFormFactory
            {
                // Occurs before the form region is initialized.
                // To prevent the form region from appearing, set e.Cancel to true.
                // Use e.OutlookItem to get a reference to the current Outlook item.
                private void VidexioFactory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
                {
                    OutlookItem = e.OutlookItem;
                }
            }

    private void btnCreate_Click(object sender, EventArgs e)

    {

    Outlook.AppointmentItem newAppointment; newAppointment = (Outlook.AppointmentItem)OutlookItem; if (newAppointment.RequiredAttendees.Count() <= 0 && (newAppointment.OptionalAttendees == null || newAppointment.OptionalAttendees.Count() == 0)) { MessageBox.Show("Please select at least 1 required attendee", "Missing Attendee", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(newAppointment.Subject)) { MessageBox.Show("Please enter a Subject", "Missing Subject", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!newAppointment.Recipients.ResolveAll()) { MessageBox.Show("Unable to resolve all attendees; please check them and try again.", "Unknown Attendee", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string firstname = ""; string lastname = ""; // Outlook.Account acc = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts[0]; firstname = ((dynamic)Globals.ThisAddIn.Application.ActiveExplorer().Session).CurrentUser.Name; if (firstname.Contains(' ')) { lastname = firstname.Split(' ')[1]; firstname = firstname.Split(' ')[0]; } string bodyText = "A test for {0}".Replace("{0}", firsname + " " + lastname); newAppointment.RTFBody = Encoding.ASCII.GetBytes(bodyText); newAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting; newAppointment.Save(); newAppointment.Close(Outlook.OlInspectorClose.olSave); //send to all attendees newAppointment.ForceUpdateToAllAttendees = true; newAppointment.Send();


    Wednesday, February 26, 2014 3:48 PM