EWS -访问共享日历项目/约会

本文关键字:约会 项目 日历 访问共享 EWS | 更新日期: 2023-09-27 18:11:59

我试图获取共享日历的所有项目(我遵循EWS -从Glen Scales访问所有共享日历),但它只列出了"共享日历"下的文件夹("Calendriers partag",因为它是法语,我找不到"Common Views"是否应该本地化,我认为不应该)。

一个同事创建了一个日历,其中有几个约会,与我共享,并给了我最大的测试权限(所有权)。

如何访问这个共享日历中的项目/约会(在c#/PowerShell中)?

更多信息:建议使用Folder。绑定,但是调用会生成一个异常:

        ExchangeService service = new ExchangeService(ExchangeVersion.ExchangeVersion);
        service.Credentials = new WebCredentials("login", "****");
        service.Url = new Uri("https://.../ews/exchange.asmx");
        try {
        FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "coworker@domain.com");
        Folder TargetFolder = Folder.Bind(service, cfolderid);     
        Console.WriteLine("target folder = " + TargetFolder);
        } catch (Exception ex){
            Console.WriteLine(ex.ToString());
        }  
Microsoft.Exchange.WebServices.Data.ServiceResponseException: Le dossier spécifié est introuvable dans la banque  d'informations.                                          
  à Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()                                                                                       
  à Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()                                                                                          
  à Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId folderId, PropertySet propertySet)                                                         
  à Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId folderId, PropertySet propertySet)                                                
  à Microsoft.Exchange.WebServices.Data.Folder.Bind(ExchangeService service, FolderId id)                                                                                
 à ConsoleApplication.Program.Main(String[] args)

附录:我重新开始使用Glen的代码,跟踪显示为注释。WlinkAddressBookEIDA为空

 static Dictionary<string, Folder> GetSharedCalendarFoldersA(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 PidTagWlinkFolderType = new ExtendedPropertyDefinition(0x684F, MapiPropertyType.Binary);
        ExtendedPropertyDefinition PidTagWlinkGroupName = new ExtendedPropertyDefinition(0x6851, MapiPropertyType.String);
        psPropset.Add(PidTagWlinkAddressBookEID);
        psPropset.Add(PidTagWlinkFolderType);
        ItemView iv = new ItemView(1000);
        iv.PropertySet = psPropset;
        iv.Traversal = ItemTraversal.Associated;
        SearchFilter cntSearch = new SearchFilter.IsEqualTo(PidTagWlinkGroupName, "Calendriers partagés"); // localized
        FindItemsResults<Item> fiResults = ffoldres.Folders[0].FindItems(cntSearch, iv);
        Console.WriteLine("fiResults TotalCount = " + fiResults.TotalCount) ; // OK -> 1
        foreach (Item itItem in fiResults.Items)
        {
            Console.WriteLine("itItem Subject = " + itItem.Subject);  // OK, my coworker shared calendar
            Console.WriteLine("itItem Id = " + itItem.Id); // Id but not the one expected!
                object WlinkAddressBookEIDA = null;
                itItem.TryGetProperty(PidTagWlinkAddressBookEID, out WlinkAddressBookEIDA);
                Console.WriteLine("WlinkAddressBookEIDA = " + WlinkAddressBookEIDA + " is null ? " + (WlinkAddressBookEIDA == null)); // KO -> WlinkAddressBookEIDA =  is null ? True
            try{[...]

EWS -访问共享日历项目/约会

我找不到"Common Views"是否应该本地化,我不这么认为)

你可以使用EWSEditor来浏览Non_IPM子文件夹,它会告诉你

一个同事创建了一个日历,其中包含一些约会,与我共享,并给了我最大的测试权限(所有权)。如何访问这个共享日历中的项目/约会(在c#/PowerShell中)?

如果你知道共享日历的人的EmailAddress,那么只需使用Mailbox的FolderId重载并直接绑定它,例如

        FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "Mailbox@domain.com");
        Folder TargetFolder = Folder.Bind(service, cfolderid);