EWS - Access Shared Calendars Items/Appointments

给你一囗甜甜゛ 提交于 2019-12-11 02:58:23

问题


I'm trying to get all items of a shared calendar (I've followed EWS - Access All Shared Calendars from Glen Scales), but it only lists Folders under "Shared Calendars" ("Calendriers partagés" as it's in French, I can't find if "Common Views" should is localized either, I don't think so).

A coworker created a calendar with a few appointments, shared it with me and gave me maximum permissions (ownership) for testing.

How do you access the Items/Appointments within this shared calendar (in C#/PowerShell)?

More info: It's recommended to use Folder.Bind, but the call generates an exception:

        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)

Addendum: I restarted with Glen's code, traces shown as comments. WlinkAddressBookEIDA is null.

 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:


I can't find if "Common Views" should is localized either, I don't think so)

It shouldn't need to be you can use the EWSEditor to browse the Non_IPM Subfolders which will tell you either way

A coworker created a calendar with a few appointments, shared it with me and gave me maximum permissions (ownership) for testing. How do you access the Items/Appointments within this shared calendar (in C#/PowerShell)?

If you know the EmailAddress of the person who has shared their calendar then just use the FolderId overload for Mailbox and bind to it directly eg

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


来源:https://stackoverflow.com/questions/39920641/ews-access-shared-calendars-items-appointments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!