none
[E2010] [EWSMA] [C#]: Getting all shared calendars from Exchange 2010

    Question

  • Hi everybody!

    I have a Exchange 2010. From there I'm trying to get all the shared calendars over EWS managed API (in  C#). I know how to get the shared calendars of a specific user, but I need a list of all calendars that are shared.

    this is how I get a specific shared calendar: 

    ExchangeService service = new ExchangeService();
    
    service.Credentials = new WebCredentials(aUName, aPwd);
    FolderId sharedFolderID = new FolderId(WellKnownFolderName.Calendar, sharedCalendarUserName);
    Folder sharedFolder = Folder.Bind(service, sharedFolderID);

    thanks for help


    • Edited by Angelo1982 Monday, February 20, 2012 11:24 AM
    Monday, February 20, 2012 9:46 AM

Answers

  • Thanks for your answer. In my case this doesen't work. It always comes up with this " Not authorised" error. I think it's because it's a hosted exchange, so I have no access to affect the rights on the server.

    But for the moment it is not a big problem. I'm doing the workaround, that the user has to enter a List of people who share their calendars. Not very beautyful but it works.

    Thanks for the help.

    Angelo


    • Edited by Angelo1982 Monday, February 27, 2012 2:53 PM
    • Marked as answer by Angelo1982 Monday, February 27, 2012 3:07 PM
    Monday, February 27, 2012 2:51 PM

All replies

  • There is nothing in EWS that will tell you that another user has shared their calendar with you (other then looking at the delegate and folder permission on every user).

    What you can do with Autodiscover is see all the Mailboxes that a user has been give full access to eg

                AutodiscoverService adAutoDiscoverService = new AutodiscoverService(ExchangeVersion.Exchange2010_SP1);
                //Define the ExchangeOnline autodiscover Endpoint
                adAutoDiscoverService.Url = new Uri(" https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc");
                adAutoDiscoverService.Credentials = new NetworkCredential(unUserName, pnPassword);
                adAutoDiscoverService.EnableScpLookup = false;
                adAutoDiscoverService.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
                adAutoDiscoverService.PreAuthenticate = true;
                GetUserSettingsResponse adResponse = adAutoDiscoverService.GetUserSettings(PrimarySTMPAddress, (new UserSettingName[1] { UserSettingName.AlternateMailboxes }));
                if (adResponse.Settings.Count >= 1)
                {
                    AlternateMailboxCollection AlternateMailboxes = (AlternateMailboxCollection)adResponse.Settings[UserSettingName.AlternateMailboxes];
                    foreach (AlternateMailbox altMailbox in AlternateMailboxes.Entries) {
                        Console.WriteLine(altMailbox.DisplayName);
                        Console.WriteLine(altMailbox.LegacyDN);
                        Console.WriteLine(altMailbox.Type);
                    }
                }

    The other thing you can do is look at the WunderBar links see http://msdn.microsoft.com/en-us/library/ee201704%28v=exchg.80%29.aspx in a user mailbox which will tell you which calendars a user has opened and work out what mailboxes these are assoicated with (eg these will contain links to PST calendars which wont be valid is EWS) eg

               FolderView fvFolderView = new FolderView(1);
                SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName,"Common Views");
                FindFoldersResults ffResults = service.FindFolders(WellKnownFolderName.Root, sfSearchFilter, fvFolderView);
                if (ffResults.Folders.Count > 0) {
                    SearchFilter sf1 = new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "IPM.Microsoft.WunderBar.Link");
                    SearchFilter sf2 = new SearchFilter.IsEqualTo(EmailMessageSchema.Subject, "Calendar");
                    SearchFilter sfCol = new SearchFilter.SearchFilterCollection(LogicalOperator.And) { sf1, sf2 };
                    ItemView ivItemView = new ItemView(1000);
                    ExtendedPropertyDefinition PR_WLINK_STORE_ENTRYID = new ExtendedPropertyDefinition(0x684E, MapiPropertyType.Binary);
                    PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_WLINK_STORE_ENTRYID };
                    ivItemView.PropertySet = psPropSet;
                    ivItemView.Traversal = ItemTraversal.Associated;
                    FindItemsResults<Item> fiResults = ffResults.Folders[0].FindItems(sfCol, ivItemView);
                    foreach (Item itItem in fiResults.Items) {
                        Object PropVal = null;
                        if(itItem.TryGetProperty(PR_WLINK_STORE_ENTRYID,out PropVal)){
                            byte[] ssStoreID = (byte[])PropVal;
                            int leLegDnStart = 0;
                            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;
                                }
                            }
                            if (lnLegDN.StartsWith("/o="))
                            {
                                NameResolutionCollection ncCol = service.ResolveName(lnLegDN, ResolveNameSearchLocation.DirectoryOnly, true);
                                foreach (NameResolution nc in ncCol)
                                {
                                    Console.WriteLine(nc.Mailbox.Address);
                                    Console.WriteLine(nc.Contact.DisplayName);
                                }
                            }
                        }
                        Console.WriteLine(itItem.Subject);                
                    }
    Cheers
    Glen
    Tuesday, February 21, 2012 5:08 AM
  • Hi Glen, thanks for the promt answer

    I tried the Autodiscover but somehow i can't get it work. 

    To make this clear: I'm trying to get the information from a Hosted Exchange 2010, not from a Microsoft Exchange Online Server. I don't know if in the end it's the same anyway. I have a Problem with the AutoDiscoverService. I always get the Error "The request failed. Remoteserver returned an Error: (401) Not authorised." I checked out the Autodiscover Service thing on MSDN and I can only find examples with urls that end with "*.xml", what's this "*.svc" ending. 

    Instead of PrimarySTMPAddress i enter the name of my domain (f.e. "hugodomain.ch") right?

    Instead of adAutoDiscoCallBack I used "RedirectionUrlValidationCallback".  

    Thanks for help! Angelo

    Tuesday, February 21, 2012 10:32 AM
  • If you have the Autodiscover DNS records setup for that domain then all you should need to do is

             AutodiscoverService adAutoDiscoverSvc = new AutodiscoverService();
             adAutoDiscoverSvc.Credentials = new NetworkCredential("user@domain.com", "password");
             adAutoDiscoverSvc.EnableScpLookup = false;
             adAutoDiscoverSvc.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
             GetUserSettingsResponse adResponse = adAutoDiscoverSvc.GetUserSettings("User@domain.com", (new UserSettingName[1] { UserSettingName.AlternateMailboxes }));
    
            private static bool adAutoDiscoCallBack(string url)
            {
                return true;
            }

    You need to use the PrimarySMTPAddress of the user you want to find the alternate mailboxes for

    Cheers
    Glen

    Wednesday, February 22, 2012 3:46 AM
  • Thanks for your answer. In my case this doesen't work. It always comes up with this " Not authorised" error. I think it's because it's a hosted exchange, so I have no access to affect the rights on the server.

    But for the moment it is not a big problem. I'm doing the workaround, that the user has to enter a List of people who share their calendars. Not very beautyful but it works.

    Thanks for the help.

    Angelo


    • Edited by Angelo1982 Monday, February 27, 2012 2:53 PM
    • Marked as answer by Angelo1982 Monday, February 27, 2012 3:07 PM
    Monday, February 27, 2012 2:51 PM