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

时间:2016-10-07 15:16:26

标签: c# powershell calendar exchangewebservices

我正在尝试获取共享日历的所有项目(我从Glen Scales跟随EWS - Access All Shared Calendars),但它只列出了“共享日历”下的文件夹(“Calendrierspartagés”,因为它是法语,我无法找到“公共视图”是否应该本地化,我不这么认为。

同事创建了一个带有几个约会的日历,与我分享并给予我最大的权限(所有权)以进行测试。

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

更多信息: 建议使用Folder.Bind,但调用会生成异常:

        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{[...]

1 个答案:

答案 0 :(得分:4)

  

我无法找到&#34; Common Views&#34;应该是本地化的,我不这么认为)

您不应该使用EWSEditor浏览Non_IPM子文件夹,它会告诉您任何一种方式

  

同事创建了一个带有几个约会的日历,与我分享并给予我最大的权限(所有权)以进行测试。   如何访问此共享日历中的项目/约会(在C#/ PowerShell中)?

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

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