Ask a questionAsk a question
 

AnswerRetrieving Attendees from Appointment

  • Wednesday, November 04, 2009 10:10 AMAditi_541 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

     

    I am creating an Appointment addin , I would need to retrieve the Attendees.

    I used the below code for retrieving the attendees and is working fine .

    But on some case these are failing example

    1.       Click on new appointment

    2.       Click on invite attendees button and add attendees

    3.       Then save the appointment , by using the below code will return the exact list of attendees

    4.       Then click on cancel invitation button  and  save

    5.       This time also the below code will give the same old attendees list

    if (ThisAddIn.ApplicationObject.ActiveInspector() != null && ThisAddIn.ApplicationObject.ActiveInspector().CurrentItem != null)

                    {

                        appointment = (OutlookInterop.AppointmentItem)ThisAddIn.ApplicationObject.ActiveInspector().CurrentItem;                 

                        OutlookInterop.Recipients recipients = (OutlookInterop.Recipients)appointment.Recipients;

                        foreach (OutlookInterop.Recipient recipient in recipients)

                        {

                            if (!string.IsNullOrEmpty(recipient.Address))

                            {

                                if (recipient.AddressEntry.Type.Equals("EX", StringComparison.CurrentCultureIgnoreCase))

                                {

                                    OutlookInterop.ExchangeUser exUser = recipient.AddressEntry.GetExchangeUser();

                                    if (!exUser.PrimarySmtpAddress.Equals(ThisAddIn.CurrentUser))

                                    attendees.Add(exUser.PrimarySmtpAddress);

                                }

                                else

                                {

                                    attendees.Add(recipient.Address);

                                }

                            }

                        }

                    }

    Please let me know whether am missing some step or doing something wrong..

     

    Thanks

    Aditi

     

Answers

  • Friday, November 06, 2009 3:36 PMHelmut ObertannerMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Aditi,

    this is typical if you don't release Item references as soon as possible and do a GC.Collect() and WaitForPendingFinalizers()
    This means that .Net caches the reference for a while and when you access the same item again, you keep a cached item reference.

    I would suggest to use an InspectorWrapper and emmbedd the code in it.
    Luckily I have a description with full sourcecode on my Blog:

    http://www.outlooksharp.de/Home/tabid/36/EntryId/44/Outlook-Inspector-Wrapper-explained.aspx

    put the code in the AppointmentItemWrapper in the Write method.
    Here you have the Item and the Inspector as Property,

    so - your code should look like this:

    OutlookInterop.Recipients recipients = (OutlookInterop.Recipients)Item.Recipients;

                        foreach (OutlookInterop.Recipient recipient in recipients)

                        {

                            if (!string.IsNullOrEmpty(recipient.Address))

                            {

                                if (recipient.AddressEntry.Type.Equals("EX", StringComparison.CurrentCultureIgnoreCase))

                                {

                                    OutlookInterop.ExchangeUser exUser = recipient.AddressEntry.GetExchangeUser();

                                    if (!exUser.PrimarySmtpAddress.Equals(ThisAddIn.CurrentUser))

                                    attendees.Add(exUser.PrimarySmtpAddress);

                                }

                                else

                                {

                                    attendees.Add(recipient.Address);

                                }

                            }

                        }
                                            recipients = null;
                        GC.Collect();
                        GC.WaitForPendingFinalizers();


    I hope that helps....

    Where does the attendees variable came from?

    Greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]

All Replies

  • Friday, November 06, 2009 12:08 PMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Aditi,

    I tried to run this code in my said. However, It failed and could not reproduce this issue. However,  I suggest that you could place this code to NewInspector event handle, and set breakpoint to debug this code. If it does not help you, would you please share us more code here? Do you have used a third party product?

    Best regards,
    Bessie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Friday, November 06, 2009 3:36 PMHelmut ObertannerMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Aditi,

    this is typical if you don't release Item references as soon as possible and do a GC.Collect() and WaitForPendingFinalizers()
    This means that .Net caches the reference for a while and when you access the same item again, you keep a cached item reference.

    I would suggest to use an InspectorWrapper and emmbedd the code in it.
    Luckily I have a description with full sourcecode on my Blog:

    http://www.outlooksharp.de/Home/tabid/36/EntryId/44/Outlook-Inspector-Wrapper-explained.aspx

    put the code in the AppointmentItemWrapper in the Write method.
    Here you have the Item and the Inspector as Property,

    so - your code should look like this:

    OutlookInterop.Recipients recipients = (OutlookInterop.Recipients)Item.Recipients;

                        foreach (OutlookInterop.Recipient recipient in recipients)

                        {

                            if (!string.IsNullOrEmpty(recipient.Address))

                            {

                                if (recipient.AddressEntry.Type.Equals("EX", StringComparison.CurrentCultureIgnoreCase))

                                {

                                    OutlookInterop.ExchangeUser exUser = recipient.AddressEntry.GetExchangeUser();

                                    if (!exUser.PrimarySmtpAddress.Equals(ThisAddIn.CurrentUser))

                                    attendees.Add(exUser.PrimarySmtpAddress);

                                }

                                else

                                {

                                    attendees.Add(recipient.Address);

                                }

                            }

                        }
                                            recipients = null;
                        GC.Collect();
                        GC.WaitForPendingFinalizers();


    I hope that helps....

    Where does the attendees variable came from?

    Greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]