当前位置: 首页 > 知识库问答 >
问题:

EWS - Access All Shared Calendars

刘英彦
2023-03-14
    private void ListCalendarFolders(ref List<EBCalendar> items, int offset)
    {
        var pageSize = 100;
        var view = new FolderView(pageSize, offset, OffsetBasePoint.Beginning);
        view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
        view.PropertySet.Add(FolderSchema.DisplayName);
        view.PropertySet.Add(FolderSchema.EffectiveRights);

        view.Traversal = FolderTraversal.Deep;

        FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.MsgFolderRoot, view);
        foreach (Folder myFolder in findFolderResults.Folders)
        {
            if (myFolder is CalendarFolder)
            {
                var folder = myFolder as CalendarFolder;
                items.Add(EBCalendar.FromEWSFolder(folder));
            }
        }

        if (findFolderResults.MoreAvailable)
        {
            offset = offset + pageSize;
            ListCalendarFolders(ref items, offset);
        }
    }

How can I get it to list all the shared calendars, and how can I get it to not include the folders that have been deleted?

共有1个答案

商开宇
2023-03-14

By Shared Calendars do you mean the calendars under the other calendars node in Outlook ?

If so these Items are NavLinks that are stored in the Common Views folder in a Mailbox which is under the NonIPMSubtree (root) see http://msdn.microsoft.com/en-us/library/ee157359(v=exchg.80).aspx.You can use EWS to get the NavLinks from a Mailbox and use the PidTagWlinkAddressBookEID extended property to get the X500 address of the Mailbox these Links refer to and then use Resolve Name to resolve that to a SMTP Address.Then all you need to do is Bind to that folder eg

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

        FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root, mbMailboxname);
        FolderView fvFolderView = new FolderView(1000);
        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, "Other 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, false);
                        if (ncCol.Count > 0)
                        {

                            FolderId SharedCalendarId = new FolderId(WellKnownFolderName.Calendar, ncCol[0].Mailbox.Address);
                            Folder SharedCalendaFolder = Folder.Bind(service, SharedCalendarId);
                            rtList.Add(ncCol[0].Mailbox.Address, SharedCalendaFolder);


                        }

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

            }
        }
        return rtList;
    }

Cheers Glen

 类似资料:
  • EWS

    我是在VB. Net中编写EWS的新手。我的目标是从到达指定收件箱的邮件中提取附件并将它们保存到指定的文件夹中。我测试了一些代码,这些代码在针对我的域/Exchange帐户使用时似乎效果很好。 然后,我创建了一个新帐户并尝试使用相同的代码。它开始产生错误: 请求失败。远程服务器返回错误:(401)未授权。 到目前为止,代码非常基本: 错误是由最后一行产生的。 到目前为止,我已经比较了工作用户和新创

  • EWS-Client 是一个Perl模块,用来调用微软的Exchange Web 服务 API,可以访问的服务包括日程和联系人信息。

  • ews-java-api 是用来访问 Exchange Web 服务的 Java 客户端库,API 支持 Office 365 Exchange Online。

  • 我正在使用EWS搜索和显示电子邮件。然而,项目的最后一步是将特定的消息保存为文件系统上的.msg文件。我知道这在EWS中是不可能的,所以我需要使用Interop.Outlook来实现这一点。我的问题是:根据EWS提供的信息,找到Outlook消息的最佳方法是什么。我尝试将通过EWS从exchange获得的Message.ID和ConversationId与Outlook的messageId关联起来

  • 这些是build中的依赖项。gradle: 下面是我目前正在测试的onCreate:

  • This problem has been bugging me for a while.When using third party email clients that use EWS you can tell that others struggle with this topic aswell.These are the things I've tried so far: > Creati