none
Display and access all Resoure Calendars RRS feed

  • Question

  • I have created resource calendars and given my account all permissions to access them. I am able to access each of these resource calendars programmatically by specifying the mailbox associated with them. But I want to first show the list of all the resource calendars available to me and then allow the user to choose which one to show meetings from.

    Example- Say I have 3 resource calendars, Resource1, Resource2, Resource3. I want to display all of these and then allow the user to choose which one he wants to see the meetings of.

    The code that I have can show meetings of a particular resource calendar only when I specify the mailbox associated with it. I would also need to find the mailbox associated with each resource calendar programmatically. Thanks for the help.

    Code for finding meetings of a particular resource calendar-

    FolderId te = new FolderId(WellKnownFolderName.Calendar, "resource1@exchange.abc.com");
    
                DateTime start = DateTime.Now;
                DateTime end = DateTime.Now.AddDays(30);
    
                CalendarView view = new CalendarView(start, end);
    
                foreach (Appointment a in service.FindAppointments(te, view))
                {
                    Console.Write("Subject: " + a.Subject.ToString() + " ");
                    Console.Write("Start: " + a.Start.ToString() + " ");
                    Console.Write("End: " + a.End.ToString());
                    Console.WriteLine();
                }

    Thursday, April 27, 2017 6:21 AM

All replies

  • I am able to get the resource calendars using Glen's code, but I cant seem to access the calendars that are shared by other users. Example -  if i have 3 resource calendars and a shared calendar all of which are in the "People's Calendars" folder, I can only retrieve the resource calendars and not the shared ones. Please help. Thank you.

    Heres the code:

    static Dictionary<string, string> GetSharedCalendarFolders(ExchangeService service, String mbMailboxname)
            {
                Dictionary<String, String> rtList = new System.Collections.Generic.Dictionary<string, String>();

                FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root, mbMailboxname);
                FolderView fvFolderView = new FolderView(int.MaxValue);
                SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Common Views");
                FindFoldersResults ffoldres = service.FindFolders(rfRootFolderid, sfSearchFilter, fvFolderView);
                if (ffoldres.Folders.Count >= 1)
                {

                    PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
                    ExtendedPropertyDefinition PidTagWlinkAddressBookEID = new ExtendedPropertyDefinition(0x6854, MapiPropertyType.Binary);
                    ExtendedPropertyDefinition PidTagWlinkGroupName = new ExtendedPropertyDefinition(0x6851, MapiPropertyType.String);

                    psPropset.Add(PidTagWlinkAddressBookEID);
                    ItemView iv = new ItemView(1000);
                    iv.PropertySet = psPropset;
                    iv.Traversal = ItemTraversal.Associated;

                    SearchFilter cntSearch = new SearchFilter.IsEqualTo(PidTagWlinkGroupName, "People's Calendars");
                    // Can also find this using PidTagWlinkType = wblSharedFolder
                    FindItemsResults<Item> fiResults = ffoldres.Folders[0].FindItems(cntSearch, iv);
                    foreach (Item itItem in fiResults.Items)
                    {
                        try
                        {
                            object GroupName = null;
                            object WlinkAddressBookEID = null;

                            // This property will only be there in Outlook 2010 and beyond
                            //https://msdn.microsoft.com/en-us/library/ee220131(v=exchg.80).aspx#Appendix_A_30
                            if (itItem.TryGetProperty(PidTagWlinkAddressBookEID, out WlinkAddressBookEID))
                            {

                                byte[] ssStoreID = (byte[])WlinkAddressBookEID;
                                int leLegDnStart = 0;
                                // Can also extract the DN by getting the 28th(or 30th?) byte to the second to last byte 
                                //https://msdn.microsoft.com/en-us/library/ee237564(v=exchg.80).aspx
                                //https://msdn.microsoft.com/en-us/library/hh354838(v=exchg.80).aspx
                                String lnLegDN = "";
                                for (int ssArraynum = (ssStoreID.Length - 2); ssArraynum != 0; ssArraynum--)
                                {
                                    if (ssStoreID[ssArraynum] == 0)
                                    {
                                        leLegDnStart = ssArraynum;
                                        lnLegDN = System.Text.ASCIIEncoding.ASCII.GetString(ssStoreID, leLegDnStart + 1, (ssStoreID.Length - (leLegDnStart + 2)));
                                        ssArraynum = 1;
                                    }
                                }
                                NameResolutionCollection ncCol = service.ResolveName(lnLegDN, ResolveNameSearchLocation.DirectoryOnly, true);
                                if (ncCol.Count > 0)
                                {
                                    //Console.WriteLine(ncCol[0].Contact.DisplayName);
                                    FolderId SharedCalendarId = new FolderId(WellKnownFolderName.Calendar, ncCol[0].Mailbox.Address);
                                    // Folder SharedCalendaFolder = Folder.Bind(service, SharedCalendarId);
                                    CalendarFolder calendar = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, ncCol[0].Mailbox.Address), new PropertySet());
                                    rtList.Add(ncCol[0].Contact.DisplayName, ncCol[0].Mailbox.Address);


                                }

                            }
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception.Message);
                        }

                    }
                }
                return rtList;
            }

    Thursday, April 27, 2017 10:03 AM