Exchange Provider: Load Calendar by Name

2 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    15 posts
    Member since:
    Jul 2012

    Posted 20 Jul 2010 Link to this post

    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;


  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 23 Jul 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top