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