none
SPCalendarView

    Question

  • Good afternoon everybody,

     

    I have to customize a SP Calendar. I need to create a new item, edit and delete as well. Also, Later, I will work with other customization. To fix thsi problem,I would like to use the SPCalendarView control. But I do not kwnow if that control will help me to get what I need. 

     

    I am working with SharePoint 2010 and Visual Studio 2010. I never worked with that control. Since I am working in a local PC which does not have installed SharePoint server, I can not see SPCalendarControl in the toolbox. I wonder if I need to include any dll to my project. I already include Microsoft.SharePoint.dll.

    Please give me a clue how to start working with my problem.

     

    Thanks for any advise or help.

     

    Jhonny M.


    Jhonny Marcelo
    • Moved by Mike Walsh FIN Saturday, August 06, 2011 6:50 AM "I am working with SharePoint 2010 and Visual Studio 2010." so it's not a Pre-SP 2010; SPD 2007 question is it? (From:SharePoint - Design and Customization (pre-SharePoint 2010))
    Friday, August 05, 2011 8:19 PM

Answers

  • Hi,

    Sharepoint control are included in the namespace of "using Microsoft.SharePoint.WebControls" which in the Microsoft.SharePoint.dll. If you added the Microsoft.SharePoint.dll successfully. One method is that you can create the SPCalendarView in code behind in you sharepoint project

    like:

    Using namespace:

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;<br/>
    
    protected override void CreateChildControls()
        {
          base.CreateChildControls();
          AddCalendar();
    
        }
    
    private void AddCalendar()
    {
     
      SPCalendarView calView = new SPCalendarView();
      calView.DataSource = GetCalendarItems;
      calView.DataBind();
      Controls.Add(calView);
    }
    
     private SPCalendarItemCollection GetCalendarItems()
        {
          SPCalendarItemCollection items = new SPCalendarItemCollection();
    
          SPCalendarItem item = new SPCalendarItem();
          item.StartDate = DateTime.Now;
          item.EndDate = DateTime.Now.AddHours(1);
          item.hasEndDate = true;
          item.Title = "First calendar item";
          item.DisplayFormUrl = "/myurl";
          item.Description = "This is a testing item";
          item.IsAllDayEvent = false;
          item.IsRecurrence = false;
    
          items.Add(item);
    
          return items;
        }
    


    Another approach is to add the SPCalendarView Control in toolbox so that we can drag and drop it like other asp.net controls. But first you need to confirm that the Microsoft.SharePoint.dll has been installed in GAC. The path is "C:\WINDOWS\assembly".

    If the dll doesn't exists. You can install it by using gacutil tool in VS command prompt:


    gacutil.exe -if "<yourfolder>/Microsoft.SharePoint.dll".

    After that, you can right click the toolbox in VS 2010->Choose Items, you can find the SPCalendarView control in .NET Framwork Components tag. Then click "OK", the control will be added in the toolbox.

    Hope this can help.

    • Proposed as answer by SharepointDummy Tuesday, August 09, 2011 1:40 PM
    • Marked as answer by Shimin Huang Monday, August 15, 2011 9:07 AM
    Monday, August 08, 2011 7:09 AM