By default, the exchange provider loads the "main" calendar of an account (DistinguishedFolderIdNameType.calendar), but I have a need to load other calendars within the same account (eg "personal", "business", etc) by their display name. I modified the exchange provider as below, and just post it here in case anyone else can make use of it.
Cheers
Jonathan
added a property to ExchangeSchedulerProvider:
public string CustomCalendarName { get; set; }
modified the constructor to accept calendar name (though should really have created overload):
added the following method to ExchangeSchedulerProvider.cs:
and then in the FindCalendarItems() method, changed
List<DistinguishedFolderIdType> folderIDs = new List<DistinguishedFolderIdType>();
DistinguishedFolderIdType ownCalendar = new DistinguishedFolderIdType();
ownCalendar.Id = DistinguishedFolderIdNameType.calendar;
folderIDs.Add(ownCalendar);
to:
List<BaseFolderIdType> folderIDs = FindCalendarFolderByName(CustomCalendarName);
Now from the aspx.cs, can set up the provider like:
Cheers
Jonathan
added a property to ExchangeSchedulerProvider:
public string CustomCalendarName { get; set; }
modified the constructor to accept calendar name (though should really have created overload):
public ExchangeSchedulerProvider(string serverUrl, string username, string password, string domain, string calendarName) : this(){ ServerUrl = serverUrl; Username = username; Password = password; Domain = domain; CustomCalendarName = calendarName;}added the following method to ExchangeSchedulerProvider.cs:
protected internal List<BaseFolderIdType> FindCalendarFolderByName(string folderName){ List<BaseFolderIdType> theReturn = new List<BaseFolderIdType>(); if (folderName == null || folderName == string.Empty) theReturn.Add(new DistinguishedFolderIdType() { Id = DistinguishedFolderIdNameType.calendar }); else { // LOOKUP THE FOLDER BY ITS FRIENDLY (DISPLAY) NAME FindFolderType findFolder = new FindFolderType(); findFolder.FolderShape = new FolderResponseShapeType() { BaseShape = DefaultShapeNamesType.IdOnly }; findFolder.Traversal = FolderQueryTraversalType.Deep; // Identify which folder to begin your search from. List<DistinguishedFolderIdType> folders = new List<DistinguishedFolderIdType>(); DistinguishedFolderIdType rootFolder = new DistinguishedFolderIdType() { Id = DistinguishedFolderIdNameType.root }; folders.Add(rootFolder); findFolder.ParentFolderIds = folders.ToArray(); // need display name property to compare against PathToUnindexedFieldType displayNamePath = new PathToUnindexedFieldType() { FieldURI = UnindexedFieldURIType.folderDisplayName }; findFolder.FolderShape.AdditionalProperties = new BasePathToElementType[] { displayNamePath }; // execute the request FindFolderResponseType response = Service.FindFolder(findFolder); // FILTER OUT THE ONE FOLDER WE'RE LOOKING FOR, AND GET ITS ID // Access the response message. ArrayOfResponseMessagesType responseMessages = response.ResponseMessages; List<string> CalendarFolderIDs = new List<string>(); foreach (ResponseMessageType responseMessage in responseMessages.Items) { if (responseMessage is FindFolderResponseMessageType) { FindFolderResponseMessageType ffrmt = (responseMessage as FindFolderResponseMessageType); FindFolderParentType ffpt = ffrmt.RootFolder; foreach (BaseFolderType item in ffpt.Folders) { if (item is CalendarFolderType) { CalendarFolderType calendarFolder = item as CalendarFolderType; if (calendarFolder != null) { if (calendarFolder.DisplayName.ToLower() == CustomCalendarName.ToLower()) { FolderIdType calID = calendarFolder.FolderId; theReturn.Add(calID); } } } } } } } return theReturn;}and then in the FindCalendarItems() method, changed
List<DistinguishedFolderIdType> folderIDs = new List<DistinguishedFolderIdType>();
DistinguishedFolderIdType ownCalendar = new DistinguishedFolderIdType();
ownCalendar.Id = DistinguishedFolderIdNameType.calendar;
folderIDs.Add(ownCalendar);
to:
List<BaseFolderIdType> folderIDs = FindCalendarFolderByName(CustomCalendarName);
Now from the aspx.cs, can set up the provider like:
ExchangeSchedulerProvider provider = new ExchangeSchedulerProvider(serverPath, _CalendarProperties.userName, _CalendarProperties.userPass, _CalendarProperties.userDomain, "myCalendar");RadScheduler1.Provider = provider;