Trying to open a shared calendar from another user and his/her calendar is NOT their default calendar.

Add-in Express™ Support Service
That's what is more important than anything else

Trying to open a shared calendar from another user and his/her calendar is NOT their default calendar.
I know this question has been sort of asked, but I have a specific issue which I haven't found the answer for. I am trying to open a shared calendar from another user and his/her calendar is NOT their default calendar. 
Stephane Touya




Posts: 4
Joined: 2015-10-05
Hi Guys,

I know this question has been sort of asked, but I have a specific issue which I haven't found the answer for. I am trying to open a shared calendar from another user and his/her calendar is NOT their default calendar.

I have tried the following:

var ns = Globals.ThisAddIn.Application.Session;

    var recip = ns.CreateRecipient("me@me.com");
    if (recip.Resolve())
    {
      var sharedCal = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderCalendar);
    }



This does not work.

I can see the shared calendar by doing the following:

private void GetCalendars()
        {

            Outlook.CalendarModule calModule = (Outlook.CalendarModule)this.Application.ActiveExplorer().NavigationPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar);


            foreach (Outlook.NavigationGroup group in calModule.NavigationGroups)

            {
                Debug.WriteLine("Calandar Folders Group  >>>>" + group.Name);


                foreach (Outlook.NavigationFolder folder in group.NavigationFolders)
                {

                    Debug.WriteLine("Calandar Folders:  >>>>" + folder.DisplayName);

                }
            }
        }


I just don't know how to open the calendar once I have the name. There is no way to get the ID using the steps above

In outlook, the calendar exists in the "Shared Calendars" navigation tree.

I am looking for a way to get the names of the Shared Calendars and then having the user select the shared calendar (E.g. From a dropdown box) and then opening that calendar.

I have found code on how to do everything else but not that specifically!

Can someone point me in the right direction??

Thanks!!
Posted 05 Oct, 2015 09:39:04 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Stephane,

You seem to look for the NavigationFolder.Folder property.


Andrei Smolin
Add-in Express Team Leader
Posted 06 Oct, 2015 03:29:49 Top
Stephane Touya




Posts: 4
Joined: 2015-10-05
Hi Andrei,

Once I get the navigation folder name, how do I get access to the calendar?


       private void GetSharedFolders()
        {
            Outlook.NameSpace ns = null;
            Outlook.Explorer activeExplorer = null;
            Outlook.NavigationPane navigationPane = null;
            Outlook.NavigationModules navigationModules = null;
            Outlook.NavigationModule navigationModule = null;
            Outlook.NavigationGroups navigationGroups = null;
            Outlook.NavigationGroup sharedCalendars = null;

            try
            {
                var appReference = GlobalVariables.App;

                ns = appReference.Session;

                activeExplorer = appReference.ActiveExplorer();
                navigationPane = activeExplorer.NavigationPane;
                navigationModules = navigationPane.Modules;


                navigationModule = navigationModules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar);


                if (navigationModule is Outlook.CalendarModule)
                {
                    navigationGroups = ((Outlook.CalendarModule)navigationModule).NavigationGroups;

                    sharedCalendars = navigationGroups["Shared Calendars"];

                    var sharedCalendarList = (from object sharedCalendar in sharedCalendars.NavigationFolders select ((Outlook.NavigationFolder) sharedCalendar).DisplayName).ToList();


                }
            }
            finally
            {
                if (activeExplorer != null)
                    Marshal.ReleaseComObject(activeExplorer);
                if (navigationPane != null)
                    Marshal.ReleaseComObject(navigationPane);
                if (navigationModules != null)
                    Marshal.ReleaseComObject(navigationModules);
                if (navigationModule != null)
                    Marshal.ReleaseComObject(navigationModule);
                if (navigationGroups != null)
                    Marshal.ReleaseComObject(navigationGroups);
                if (sharedCalendars != null)
                    Marshal.ReleaseComObject(sharedCalendars);
                if (ns != null)
                    Marshal.ReleaseComObject(ns);
            }
        }




Thanks,

Stephane
Posted 06 Oct, 2015 09:19:33 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Stephane Touya writes:
get access to the calendar


Sorry? What do you mean?


Andrei Smolin
Add-in Express Team Leader
Posted 06 Oct, 2015 09:22:09 Top
Stephane Touya




Posts: 4
Joined: 2015-10-05
How do I get access to the calendar to enumerate the appointment items. The following does not seem to work.


public void GetAppointItemsForSelectedCalendar(string selectedCalendar)
        {
            Outlook.Items calendarItems = null;
            Outlook.NameSpace ns = null;

            if (selectedCalendar == null)
                return;

            try
            {
                ns = Globals.ThisAddIn.Application.Session;

                var calendarFolderRoot = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

                var selectedFolder = calendarFolderRoot.Folders[selectedCalendar)];

                calendarItems = selectedFolder.Items;

                foreach (var calendarItem in calendarItems)
                {
                    var appointmentItem = (Outlook.AppointmentItem)calendarItem;


                    if (appointmentItem.MessageClass == "IPM.Appointment")
                    {

.....


When I call GetAppointItemsForSelectedCalendar with anything with in the sharedCalendarList (from the previous post) it cannot find the calendar.

Thanks!
Posted 06 Oct, 2015 09:46:13 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Stephane,

Stephane Touya writes:
var selectedFolder = calendarFolderRoot.Folders[selectedCalendar)];


Did you try to get that folder using NavigationFolder.Folder?

Also, it is strongly recommended to release every COM object created in your code. For that reason, it is recommended to use for loops (not foreach loops) on COM collections. You may find that blog useful: https://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/.


Andrei Smolin
Add-in Express Team Leader
Posted 07 Oct, 2015 01:49:55 Top
Stephane Touya




Posts: 4
Joined: 2015-10-05
Hi Andrei,

Thanks for your help! I got the info I needed by using the following:

  var sharedCalendarFolder = ((Outlook.NavigationFolder)sharedCalendar).Folder;


I also updated the code to use for loops so that I can release every COM object!!

Stephane
Posted 07 Oct, 2015 08:49:41 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Stephane,

Thank you for letting us know.
Posted 09 Oct, 2015 05:25:42 Top