jj.doe
jj.doe

Reputation: 13

GetSharedDefaultFolder() always return inbox regardless of FolderType provided

I am trying to retrieve shared calendars from outlook in c#, using the example provided here (Display a shared calendar of a recipient)

The attempt to iterate through folder.Items by doing an foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems) has always resulted in a COM exception.

After some trial and error, I've noticed that the .GetSharedDefaultFolder() has been always returning inbox folder instead of calendar, despite passing in the right folder type...

Here is relevant code (or what I think is relevant at least...). Noticed that CalendarFolder.DefaultMessageClass is always IPM.NOTE. When making GetSharedDefaultFolder() call with my own email address (currently signed in user of outlook), DefaultMessageClass is IPM.Appointment correctly.

I can access the selected users shared folder using Outlook GUI from "Open Other Users's Folder" - select folder type calendar in the dropdown.

AddressEntry addrEntry =
            oApp.Session.CurrentUser.AddressEntry;
        if (addrEntry.Type == "EX")
        {
            ExchangeUser manager =
                oApp.Session.CurrentUser.
                    AddressEntry.GetExchangeUser().GetExchangeUserManager();
            if (manager != null)
            {
                Recipient recip =
                    oApp.Session.CreateRecipient(manager.Name);
                if (recip.Resolve())
                {
                    try {
                        CalendarFolder =
                            oApp.Session.GetSharedDefaultFolder(
                                    recip, OlDefaultFolders.olFolderCalendar)
                                as Folder;
                        Console.WriteLine($"{manager.Name}'s: " + CalendarFolder.DefaultMessageClass);
                    }
                    catch (System.Exception ex )
                    {
                        Console.Write(ex);
                    }
                }
            }
        }

Upvotes: 0

Views: 742

Answers (1)

jj.doe
jj.doe

Reputation: 13

Solved.

Of course I didn't read the method details page close enough.....https://learn.microsoft.com/en-us/office/vba/api/outlook.namespace.getshareddefaultfolder

"This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders (for example, their shared Calendar folder)."

I was not a delegate.

Upvotes: 0

Related Questions