This is a migrated thread and some comments may be shown as answers.

Exchange Provider: Load Calendar by Name

1 Answer 112 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 2
Jonathan asked on 20 Jul 2010, 05:36 PM
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):

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;


1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 23 Jul 2010, 02:01 PM
Hi Jonathan,

Thanks for sharing your code with the community. I have updated your Telerik points for this.

Greetings,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Scheduler
Asked by
Jonathan
Top achievements
Rank 2
Answers by
Peter
Telerik team
Share this question
or