0

I am creating a appointment checker on outlook shared calendars by picking up the profiles from a inifile. It picks the first shared calendar but when it loops to the second, it gives me a null reference exception error. Can you advice what I am doing wrong.

Should the outlook recip be a list? Would appreciate some help

string CalendarName = iniFile.GetValue("Appointmentdays", "Calendarname");
List<string> names = CalendarName.Split(',').Reverse().ToList();

foreach (var name in names)
        //for (var i = 0; i < names.Count; i++)
        {
            //Create Recipient

            Outlook.Recipient recip =  oApp.Session.CreateRecipient(name);
            Outlook.MAPIFolder CalendarFolder = oNS.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderCalendar);
            String oCalendarName = CalendarFolder.Name;
            String oCalendarEntryID = CalendarFolder.EntryID;
        }
edcoder
  • 503
  • 1
  • 5
  • 19
  • Firstly, which lines gives you the error? – Dmitry Streblechenko Sep 19 '18 at 15:55
  • Outlook.Recipient recip = oApp.Session.CreateRecipient(name); – edcoder Sep 20 '18 at 11:29
  • Thank you Dmitry, The above line gives me an error. I think my question is more, how to loop through the outlook recipients – edcoder Sep 20 '18 at 11:55
  • That means oApp.Session is null. After crating oApp, retrieve the Namespace object from oApp.GetNamespace("MAPI"), then call Namespacee.Logon instead of using oApp.Session. – Dmitry Streblechenko Sep 20 '18 at 14:45
  • Hi Dmitry, thank you for helping me out. I have added an image of the issue that I am having in my code to the question. The problem for me is that I am able to loop through the first name perfectly fine, when it tries to loop through the second names and there after it gives me the error. – edcoder Sep 21 '18 at 07:09
  • I see that you are the expert. Wonderful tools you've made..I will give them a try :). I am trying to find your email to connect with you but cant find it. Just to explain more about what I am developing. – edcoder Sep 21 '18 at 07:12

0 Answers0