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

using sharepoint calendar list as the datasource

3 Answers 173 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Tanuj
Top achievements
Rank 1
Tanuj asked on 15 Jan 2009, 05:25 PM
need sample code (C#) to display events from a sharepoint(WSS 3.0) calendar list onto a scheduler. basically i want to use a sharepoint list as the datasource, also need reccurring events to be displayed.

3 Answers, 1 is accepted

Sort by
0
Dimitar Milushev
Telerik team
answered on 20 Jan 2009, 06:11 PM
Hello Tanuj,

Here is a sample Web Part that uses RadSCheduler to display a Sharepoint Calendar List.

public class SchedulerWebPart : System.Web.UI.WebControls.WebParts.WebPart 
    private SPCalendarView _view; 
    private SPWeb oWeb; 
 
    //For DropDown List (Show all or selected member)   
    private Label lblShowAll; 
    private Label lblMember; 
 
    SPListItemCollection ListItemCol; 
    SPCalendarItem CalItem; 
 
    /****************************************** 
     * Intilaize DropDownList and RADSchedulder 
     *****************************************/ 
 
    private DropDownList allUsers = new DropDownList(); 
    private RadScheduler theScheduler = null
 
    protected override void OnLoad(EventArgs e) 
    { 
        base.OnLoad(e); 
 
        /***************************************************** 
         * Check for all USERS (Memeber)the in SharePoint Grp. 
         ****************************************************/ 
 
        oWeb = SPControl.GetContextWeb(Context); 
        oWeb.AllowUnsafeUpdates = true
 
        allUsers.AutoPostBack = true
        allUsers.EnableViewState = true
 
        allUsers.Items.Insert(0, new ListItem("--All users--", "0")); 
 
        foreach (SPUser user in oWeb.AllUsers) 
        { 
            allUsers.Items.Add(user.Name); 
        } 
 
        this.Controls.Add(this.allUsers); 
 
        allUsers.SelectedIndexChanged += new EventHandler(allUsers_SelectedIndexChanged); 
 
        /************************************************************** 
         * Create the table that will hold the toolbar and the calendar 
         **************************************************************/ 
 
        HtmlTable theMainTable = new HtmlTable(); 
        theMainTable.Width = "100%"
        theMainTable.CellPadding = 0
        theMainTable.CellSpacing = 0
        theMainTable.Border = 0
        this.Controls.Add(theMainTable); 
 
        // Create the row and the cell for the calendar   
        HtmlTableRow calendarRow = new HtmlTableRow(); 
        theMainTable.Rows.Add(calendarRow); 
        HtmlTableCell calendarCell = new HtmlTableCell(); 
        calendarRow.Cells.Add(calendarCell); 
 
        CheckScriptManager(); 
 
        theScheduler = new RadScheduler(); 
        theScheduler.Skin = "Office2007"
        // Disable the timeline view   
        theScheduler.TimelineView.UserSelectable = false
        theScheduler.Width = new Unit(800, UnitType.Pixel); 
        theScheduler.Height = new Unit(600, UnitType.Pixel); 
        theScheduler.OverflowBehavior = OverflowBehavior.Expand; 
        //theScheduler.Provider = new ListSchedulerProvider();   
        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
 
 
        //Attaching Telerik RADScheduler    
        theScheduler.DataSource = GetCalendarItems(); 
 
        theScheduler.DataStartField = "StartDate"
        theScheduler.DataEndField = "StartDate"
        theScheduler.DataSubjectField = "Title"
        theScheduler.DataKeyField = "ItemID"
 
        this.Controls.Add(theScheduler); 
 
    } 
 
    private ScriptManager CheckScriptManager() 
    { 
        ScriptManager sm = ScriptManager.GetCurrent(Page); 
        if (sm == null) 
        { 
            if (Page.Form != null) 
            { 
                sm = new ScriptManager(); 
                sm.ID = Page.Form.ID + "_ScriptManager"; 
                Page.Form.Controls.Add(sm); 
            } 
        } 
 
        return sm; 
    } 
 
    protected override void CreateChildControls() 
    { 
        base.CreateChildControls(); 
 
        // TODO: add custom rendering code here.   
        Label label = new Label(); 
        label.Text = "SPCalendarWP Demo!"
        this.Controls.Add(label); 
    } 
 
    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["Events"]; 
        SPView oView = oCalendarList.Views["Calendar"]; 
 
        SPCalendarView calendarView = new SPCalendarView(); 
        string strListCalendar = "Calendar"
 
        SPQuery query = new SPQuery(); 
        query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy>"
 
 
        if (allUsers.SelectedItem.Value == "0") //Show All   
        { 
            query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy>"
        } 
        else 
        { 
            query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy><Where><Eq><FieldRef Name='Absentee' /><Value Type='User'>" + allUsers.SelectedItem.Text + "</Value></Eq></Where>"; 
        } 
 
 
        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(); 
 
            items.Add(calItem); 
 
        } 
 
        // return the collection   
        return items; 
    } 
 
    void allUsers_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        if (allUsers.SelectedItem.Value != "-1") 
        { 
            try 
            { 
                if (allUsers.SelectedItem.Value == "0") // Show All      
                { 
                    lblShowAll.Text = "Show All"
                    this.Controls.Add(lblShowAll); 
                } 
                else 
                { 
                    lblMember.Text = allUsers.SelectedItem.Text; 
                    this.Controls.Add(lblMember); 
 
                } 
            } 
            catch (Exception ex) 
            { 
            } 
        } 
 
    }   
 


All the best,
Dimitar Milushev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Gary
Top achievements
Rank 1
answered on 19 Nov 2018, 04:51 PM

Hi,

Is there an example of how to display the Scheduler using SharePoint REST calls with javascript/JQuery (Json)?  Thank you.

0
Gary
Top achievements
Rank 1
answered on 20 Nov 2018, 11:56 AM

Hi,

Is there an example of how to display the Scheduler using SharePoint REST calls with javascript/JQuery (Json)?  Thank you

Tags
Scheduler
Asked by
Tanuj
Top achievements
Rank 1
Answers by
Dimitar Milushev
Telerik team
Gary
Top achievements
Rank 1
Share this question
or