RADScehduler & SharePoint recurrence

Thread is closed for posting
6 posts, 0 answers
  1. A8D7E1F4-D5C7-4C1F-B0C3-BD86F51C6037
    A8D7E1F4-D5C7-4C1F-B0C3-BD86F51C6037 avatar
    7 posts
    Member since:
    Oct 2008

    Posted 19 Feb 2009 Link to this post

    Requirements

    RadControls version  2008.3.1217.20

     

    .NET version: 3.5

     

    Visual Studio version: 2008

     

    programming language: C#

     

    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    This projects explains the usage of RADScheduler and backed by SharePoint calendar list as database. 
    Its easy to attach RADScheduler to SharePoint calendar list as database but when it comes recurrence developers faces lot of problems. Moreover, Telerik recurrence engine and SharePoint recurrence engine are quite different. 

    A complex solution to fix it. 

    What can we do is that: 
    1) SharePoint calendar list to iCal format. (using feature and lot of coding to export to iCal format)
    2) Importing to the iCal data into RadScheduler

    This solution looks very complex. 

    Problem with the solution:
    1) Its fairly complex and we have to add one more feature.
     2) Adding one feature just for recurrence will make the application more complex. 

    Solution: 

    It can be solved it using CAML queries and its much more simpler and easy to code rather than creating one more feature. Here is the approach: 

    1) For calendar items (for e.g. Team members in my case),  filter out all recurrent events. (NON RECURRENT)
    2) For recurrent items, I am filtering other calendar items. (RECURRENT)

    Thus, RADScheduler will display both: individual calendar items (for e.g. team members) and recurrent events (for e.g. Team meeting on every monday).

    Creating 2 CAML queries: one for calendar items (not recurrent) and second is for recurrent items (not selecting other calendar items which are not recurrent)

    Using this approach there is no additional feature just for recurrence.

    There is my code and it will be useful for other SharePoint Developers who are using RADScheduler backed by SharePoint calendar list.

    1) CAML queries
    private SPCalendarItemCollection GetCalendarItems()     
            {     
                // Create a new collection for the calendar items       
                // This is an item with a start and end date.       
                SPCalendarItemCollection items = new SPCalendarItemCollection();     
        
                oWeb = SPControl.GetContextWeb(Context);     
                SPList oCalendarList = oWeb.Lists["Calendar"];     
                SPView oView = oCalendarList.Views["Calendar"];     
        
                SPQuery query = new SPQuery();     
                query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy>";     
        
        
                if (allUsers.SelectedItem.Value == "0"//Show All       
                {     
                    query.Query = "<Where><Eq><FieldRef Name='fRecurrence' /><Value Type='Recurrence'>0</Value></Eq></Where><OrderBy><FieldRef Name='ID' /></OrderBy>";     
                }     
                else    
                {     
                    query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy><Where><And><Eq><FieldRef Name='Absentee' /><Value Type='User'>" + allUsers.SelectedItem.Text + "</Value></Eq><Eq><FieldRef Name='fRecurrence' /><Value Type='Recurrence'>0</Value></Eq></And></Where>";     
                }     
        
                //For Team members (not for recurrent events)     
                foreach (SPListItem listItem in oCalendarList.GetItems(query))     
                {     
                    SPCalendarItem calItem = new SPCalendarItem();     
                    calItem.ItemID = listItem["ID"].ToString();     
                    calItem.Title = listItem["Title"].ToString();     
                    calItem.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);     
                    calItem.StartDate = (DateTime)listItem["Start Time"];     
                    calItem.ItemID = listItem.ID.ToString();     
        
                    if (listItem["End Time"] != null)     
                    {     
                        calItem.hasEndDate = true;     
                        calItem.EndDate = (DateTime)listItem["End Time"];     
                    }     
                    else    
                        calItem.hasEndDate = false;     
        
                    if (listItem["Description"] != null)     
                        calItem.Description = listItem["Description"].ToString();     
        
                    if (listItem["Location"] != null)     
                        calItem.Location = listItem["Location"].ToString();     
        
                    calItem.IsRecurrence = Convert.ToBoolean(listItem["Recurrence"]);     
        
                        
                    items.Add(calItem);     
        
                }     
        
                //Only for Reccurent events (like weekley meetings)     
                SPQuery queryRecurrence = new SPQuery();     
                queryRecurrence.ExpandRecurrence = true;     
                queryRecurrence.Query = "<Where>" +      
                                           "<And>" +       
                                              "<Eq>"+      
                                                 "<FieldRef Name='fRecurrence' />" +     
                                                 "<Value Type='Recurrence'>1</Value>" +     
                                              "</Eq>" +      
                                              "<DateRangesOverlap>" +     
                                                 "<FieldRef Name='EventDate' />"+     
                                                 "<FieldRef Name='EndDate' />"+     
                                                 "<FieldRef Name='RecurrenceID' />" +     
                                                     "<Value Type='DateTime'>"+     
                                                        "<Month />"+     
                                                     "</Value>" +     
                                              "</DateRangesOverlap>"+     
                                           "</And>" +     
                                        "</Where>"+     
                                        "<ViewFields>"+     
                                           "<FieldRef Name='Title' />"+     
                                           "<FieldRef Name='EventDate' />"+     
                                           "FieldRef Name='EndDate' />"+      
                                           "<FieldRef Name='fRecurrence' />"+     
                                           "<FieldRef Name='Absentee' />"+     
                                        "</ViewFields>";     
                     
                // Look forward from the beginning of the current month     
                queryRecurrence.CalendarDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);     
        
                // Returns all items (including recurrence instances) that     
                // would appear in the calendar view for the current month     
        
                SPListItemCollection calendarItems = oCalendarList.GetItems(queryRecurrence);     
        
                foreach (SPListItem listItem in oCalendarList.GetItems(queryRecurrence))     
                {     
                    SPCalendarItem calItem = new SPCalendarItem();     
                    calItem.ItemID = listItem["ID"].ToString();     
                    calItem.Title = listItem["Title"].ToString();     
                    calItem.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);     
                    calItem.StartDate = (DateTime)listItem["Start Time"];     
                    calItem.ItemID = listItem.ID.ToString();     
        
                    if (listItem["End Time"] != null)     
                    {     
                        calItem.hasEndDate = true;     
                        calItem.EndDate = (DateTime)listItem["End Time"];     
                    }     
                    else    
                        calItem.hasEndDate = false;     
        
                    if (listItem["Description"] != null)     
                        calItem.Description = listItem["Description"].ToString();     
        
                    if (listItem["Location"] != null)     
                        calItem.Location = listItem["Location"].ToString();     
        
                    items.Add(calItem);     
                }     
        
        
                // return the collection       
                return items;     
            }    
     
     
     

    2) Web Part using the RADScheduler: 
     
    protected override void OnLoad(EventArgs e)  
            {  
                base.OnLoad(e);  
     
                // TODO: add custom rendering code here.    
                Label label = new Label();  
                label.Text = "";  
                this.Controls.Add(label);  
     
                /*****************************************************
                 * Check for all USERS (Memeber)the in SharePoint Grp.
                 ****************************************************/ 
     
                //allUsers = new DropDownList();  
                allUsers = new RadComboBox();  
                allUsers.ID = "AllUsers";  
                allUsers.Width = 180;  
                allUsers.AutoPostBack = true;  
                this.Controls.Add(this.allUsers);  
     
                // Only create the list items once. On the next postback  
                // they will be recreated from the ViewState.  
                if (allUsers.Items.Count == 0)  
                {  
                    //allUsers.Items.Insert(0, new ListItem("--All Members--", "0"));  
                    allUsers.Items.Insert(0, new RadComboBoxItem("--All Members--""0"));  
     
                    foreach (SPUser user in oWeb.Groups["ZIT - Development"].Users)  
                    {  
                        //allUsers.Items.Add(user.LoginName);  
                        allUsers.Items.Add(new RadComboBoxItem(user.Name));  
                    }  
                }  
     
                theScheduler = new RadScheduler();  
                theScheduler.ID = "TheScheduler";  
                //theScheduler.Skin = "Office2007";  
                theScheduler.Skin = "Vista";  
     
                // Enable the timeline view    
                theScheduler.TimelineView.UserSelectable = true;  
                theScheduler.Width = new Unit(740, UnitType.Pixel);  
                theScheduler.Height = new Unit(650, UnitType.Pixel);  
                theScheduler.OverflowBehavior = OverflowBehavior.Expand;  
     
                theScheduler.SelectedView = SchedulerViewType.MonthView;  
     
                // The following line plus the CSS classes added in the Default.aspx    
                // caused the appointments to cross the boundary of the month cell    
                theScheduler.MonthView.VisibleAppointmentsPerDay = 5;  
                theScheduler.EnableViewState = false;  
     
                theScheduler.StartEditingInAdvancedForm = true;  
                theScheduler.StartInsertingInAdvancedForm = true;  
     
                theScheduler.AllowDelete = false;  
     
                /*****************************************************************************************
                 * For overriding SharePoint forms (new/edit) and not using RADScheduler new/edit forms.
                 *****************************************************************************************/ 
                theScheduler.FormCreating += new SchedulerFormCreatingEventHandler(theScheduler_FormCreating);  
                theScheduler.TimeSlotCreated += new TimeSlotCreatedEventHandler(theScheduler_TimeSlotCreated);  
     
                //Attaching Telerik RADScheduler     
                theScheduler.DataSource = GetCalendarItems();  
     
                theScheduler.DataStartField = "StartDate";  
                theScheduler.DataEndField = "EndDate";  
                theScheduler.DataSubjectField = "Title";  
                theScheduler.DataKeyField = "ItemID";  
     
     
                this.Controls.Add(theScheduler);  
     
                //allUsers.SelectedIndexChanged += new EventHandler(allUsers_SelectedIndexChanged);  
                allUsers.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(allUsers_SelectedIndexChanged);  
     
                ajaxManager = RadAjaxManager.GetCurrent(Page);  
                if (ajaxManager == null)  
                {  
                    ajaxManager = new RadAjaxManager();  
                    ajaxManager.ID = "RadAjaxManager1";  
                    Controls.Add(ajaxManager);  
                    Page.Items.Add(typeof(RadAjaxManager), ajaxManager);  
     
                    //For "loading text" while server retrives the filtered name  
     
                    loadingPanel = new RadAjaxLoadingPanel();  
                    loadingPanel.Transparency = 30;  
                    loadingPanel.BackColor = System.Drawing.Color.LightGray;  
                    Controls.Add(loadingPanel);  
     
                    System.Web.UI.WebControls.Image background = new System.Web.UI.WebControls.Image();  
                    background.ImageUrl = "http://demos.telerik.com/aspnet-ajax/Ajax/img/loading7.gif";  
                    background.BorderWidth = Unit.Pixel(0);  
                    background.AlternateText = "Loading...";  
                    background.Style[HtmlTextWriterStyle.MarginTop] = "50px";  
                    loadingPanel.Controls.Add(background);  
     
                }  
     
                ajaxManager.AjaxSettings.AddAjaxSetting(theScheduler, theScheduler, loadingPanel);  
                ajaxManager.AjaxSettings.AddAjaxSetting(allUsers, theScheduler, loadingPanel);  
     
            } 

    Happy Programming
    Aroh Shukla
  2. A8D7E1F4-D5C7-4C1F-B0C3-BD86F51C6037
    A8D7E1F4-D5C7-4C1F-B0C3-BD86F51C6037 avatar
    7 posts
    Member since:
    Oct 2008

    Posted 20 Feb 2009 Link to this post

    Hi Veselin, 

    I could not comprehend the language for your post. 
    Please let me know if my previous code does not "comply" to Telerik "code library". 

    Thank you. 

    Best regards, 
    Aroh Shukla
     
  3. 05298DA3-0128-4279-9FF0-2B4BB873F19F
    05298DA3-0128-4279-9FF0-2B4BB873F19F avatar
    555 posts
    Member since:
    Sep 2012

    Posted 23 Feb 2009 Link to this post

    Hi Aroh,

    Please, excuse us, this was supposed to be an internal message.

    Thank you for this code. It should prove useful for others that need the similar functionality. As token of our gratitude, I have updated your Telerik points.

    All the best,
    Dimitar Milushev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. 9F5C81CF-DE71-4F36-95CA-9A4767F9D748
    9F5C81CF-DE71-4F36-95CA-9A4767F9D748 avatar
    9 posts
    Member since:
    Nov 2009

    Posted 09 Dec 2009 Link to this post

    that's greate! I wonder how to add/modify/delete appointments in your web part.

    Thanks
    Jerry
  5. 61D77A9B-1C06-4A7C-8FDE-B00C3446618A
    61D77A9B-1C06-4A7C-8FDE-B00C3446618A avatar
    33 posts
    Member since:
    Feb 2011

    Posted 08 Aug 2011 Link to this post

    Guys, 

    How I Can use the Edit/Add/Display form from sharepoint 2010 in the RadSchedure?

    thank!s!


    I saw the example 

    RADScehduler & SharePoint recurrence but does not implement the events

                theScheduler.FormCreating += new SchedulerFormCreatingEventHandler(theScheduler_FormCreating);  

               theScheduler.TimeSlotCreated += new TimeSlotCreatedEventHandler(theScheduler_TimeSlotCreated);  



  6. 8AECA7A5-3E26-4708-AD62-47AA92940523
    8AECA7A5-3E26-4708-AD62-47AA92940523 avatar
    6637 posts
    Member since:
    Sep 2012

    Posted 11 Aug 2011 Link to this post

    Hi,

    Please, see this help topic -
    http://www.telerik.com/help/aspnet-ajax/moss-display-and-edit-appointments.html

    Kind regards,
    Peter
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.