EWS – 访问所有共享日历

我有以下代码:

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); } } 

service是一个ExchangeService实例。 不幸的是,它仍然列出了已被删除的文件夹,并没有列出共享的日历。

我怎样才能得到它列出所有的共享日历,我怎样才能得到它不包括已被删除的文件夹?

“共享日历”是指Outlook中其他日历节点下的日历吗?

其他日历节点

如果是这样,这些项目是存储在NonIPMSubtree(root)下的邮箱中的Common Views文件夹中的NavLink,请参阅http://msdn.microsoft.com/en-us/library/ee157359(v=exchg.80); .aspx 。 您可以使用EWS从邮箱中获取NavLink,并使用PidTagWlinkAddressBookEID扩展属性获取这些链接引用的邮箱的X500地址,然后使用“parsing名称”将其parsing为SMTP地址。 然后,你需要做的就是绑定到该文件夹​​,例如

  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; } 

干杯格伦

你需要指定一个searchfilter。 这是在这里描述,虽然我不知道哪个Schema是正确的,我的猜测将是Archieved。

所以你会做这样的事情:

 SearchFilter searchFilter = new SearchFilter.IsEqualTo(FolderSchema.Archieved, false); FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.MsgFolderRoot,searchFilter, view); 

格伦邮政是完美的,但绑定文件夹给出错误。 但我解决了这个问题。 而不是这一行:

 Folder SharedCalendaFolder = Folder.Bind(service, SharedCalendarId); 

使用以下行来共享文件夹绑定

 CalendarFolder calendar = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, OwnerEmailAddress), new PropertySet()); 

这里OwnerEmailAddress是所有者的电子邮件地址,或者如果使用Glen的代码,你可以写ncCol [0] .Mailbox.Address。