SharePoint 2010 & 2013 – Meeting Room Booking Web Part Source Code.

A common usage for SharePoint is meeting room bookings.

This article will provide one way of elegantly handling this scenario with some simple configuration. It provide a custom web parts for both SharePoint 2010 and SharePoint 2013, with full source code for both web parts along with the instruction on how to make it work.

The web part contains the following features:

  • SharePoint out of the box calendar
  • Custom List for rooms listing
  • Ability to filter by rooms title
  • Handle repeating events and Prevent double booking
  • In a later post we will add functionality to display booked rooms colored by the room color

Task1: Create Rooms List

  • Create a custom List called Rooms. This will contain the list of all available rooms. Later, we will add functionality to add a specific color for each room.

Task 2: Create Meeting Room calendar List

  • Make sure that “Team Collaboration Lists” feature is activated in Site Settings -> Site Features
  • Create new list of type Calendar and name it: “MeetingRoom

  • Go to MeetingRoom -> List Settings, click on Create Column, set the below properties
    • Column Name: Room
    • Lookup
    • Required field
    • Get Information from list Rooms
    • Show Columns: Title, ID


Task 3: Deploy and Add Web Part

  • Download SharePoint 2010 web part source code from here. Download SharePoint 2013 web part source code from here.
  • Open with Visual Studio, put your Site URL property and click on deploy. (You can instead have the WSP file from the bin folder and add the solution from PowerShell or using the STSADM command)
  • Make sure that site collection feature BookingRoom.Web is activated
  • Navigate to MeetingRoom page (/lists/meetingRoom)
  • Click on Edit Page -> Add a Web Part -> Select BookingRoom from custom web parts category and click on Add
  • Go to Web Part properties and set Calendar Webpart Title to calendar title


Task 4: Enable Session State

  • Go to Web.Config locate enableSessionState and set value equal to
    true
  • Ensure that the remove and add lines exist in the modules section for Session.

     

    • <modules
      runAllManagedModulesForAllRequests=true>


    • <remove
      name=Session />

    • <add
      name=Session
      type=System.Web.SessionState.SessionStateModule
      preCondition=“” />


    • modules>

  • Do an IISRESET

Task 5: Test Web Part

  • Add some items in the rooms list
  • Navigate to MeetingRoom page (/lists/meetingRoom)
  • Check the rooms added are listed and there is no error message
  • Try to add a new item and check if the below test cases are correct
    • Prevent booking rooms in the past
    • Prevent booking the same room in conflicting times. If we consider that Room A is already booked on 13/6/13 from 8 am to 10 am. Therefore the system must prevent booking room A on 13/6/13 on the below times:
      • From before 8 am to after 8 am
      • From below 10 am to after 10 am
    • Check repeating event and check same logic on the above case
    • Check if other than the above cases, the Item is added and shown on the calendar
  • Add many items and check if the filter button in working properly

Screen Shots

  • Default View

  • Add new booking

  • Reservation Conflict

  • Reservation occurs in the past

  • Filtered by Room A

  • Filtered by Room B and Room C

 

Download SharePoint 2010 web part source code from here.

Download SharePoint 2013 web part source code from here.

 

About the Author

Dany Hoyek
I am a Computer and Communication Engineer and Consultant. I have been leading, developing and managing millions of dollars worth of software development projects.
  • Tony Tannous

    Great Job Dany, this post help me a lot, keep on posting such intresting topics.

  • Dinooz

    From Powershell add the solution, install it in the SiteCollection.

    Add-SPSolution -LiteralPath “C:\BookingRoom13\BookingRoom\BookingRoom\bin\Debug\BookingRoom.wsp”

    Install-SPSolution -Identity BookingRoom.wsp -GACDeployment -WebApplication http://yoursite.sharepiont2013.com

    Got ot the Site Collection Features and activate it…..

    PS C:\powershell> Get-SPSessionStateService

    Enabled Timeout Database Server Database Catalog Database Id
    ——- ——- ————— —————- ———–
    False 01:00:00

    PS C:\powershell> Enable-SPSessionStateService –DefaultProvision

    PS C:\powershell> Get-SPSessionStateService

    Enabled Timeout Database Server Database Catalog Database Id
    ——- ——- ————— —————- ———–
    True 01:00:00 SPDBAliasTCP SessionStateServi… 7539837b-1463-424f-b98d-64266d19f9ab

    Ok so its specific to “Rooms” and “MeetingRoom” but unfortunately found the FilterWebpart break the page in 2013…. have to recover from it with the URL and
    http://yoursite.sharepoint2013.com/meeting_rooms/Lists/MeetingRoom/calendar.aspx?Contents=1
    To enter in webpart maintenance and remove the Filter Webpart…
    Leave the ListView webpart is the one that runs the validations.

    Overall the webpart solution works great. I like to have the posiblity of enable/disable meetings in the past.
    Also the image link is broken on the alert for double booking and also will be incredible useful the fact to not have to be limited to the specific names for “Rooms” and “MeetingRoom”. the example is custom permissions on the Calendar Lists pointing to different calendars.

    keep doing the great job and look forward to follow your work. R U in google+ ???

    • Dany H

      Thank you for your comment. I agree with all the issues you have discussed as this was done in a hurry in 1 day for a friend of mine. I am currently overwhelmed with other projects but I will look into it as soon as I have some time.

      Also if I remember correctly, you can change the “Rooms” and “MeetingRoom” names from the webpart properties.

  • sidu

    it’s work on sharepoint Online? i use office 365

    • Dany Hoyek

      Hi, I haven’t been able to test this on SharePoint online but it cannot be installed as a sandbox solution.

  • K. Killebrew

    Thanks so much for sharing this. Here’s a couple of changes I made to get things up and running in SharePoint 2013:
    – In BookingRoom.ascx.cs, I removed the bits around line 180 that save the view to the session; I was getting errors about having a non-serializable object, and SPView is non-serializable. I just added this line instead:
    SPView originalCalendarWebPartView = calendarList.Views[CustomProperties.CalendarDefaultView];

    -To get content approval working for the events, I modified the ItemUpdating method in PreventBookingConflict.cs to check the moderation status:
    var moderationStatus = (SPModerationStatusType)properties.AfterProperties[“vti_doclibmodstat”];
    if (properties.List.Title == CALENDAR_LIST_NAME && properties.ListItemId != 0 && moderationStatus == SPModerationStatusType.Pending)
    {
    TimeConflict(properties);
    }

    • Dany Hoyek

      Hello, I haven’t faced the issue you mentioned, however I am glad you find this helpful and thanks for sharing your improvements

  • karl

    I am new to VS and webparts, received the error below and am unable to manually install the certificate due to password protection. Can you point me in the right direction?

    Error 4 Cannot import the following key file: Key.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_ADD29956BC4E7629 BookingRoom.ComponentModel

    • Dany Hoyek

      I believe you can easily remove the key and add another one. Thus the old key is P@$$w0rd

  • Hi. thanks for this web part as I urgently needed it for a SharePoint 2013 site. I wasn’t able to get the “Filter” By button to work as adding the web part doesn’t appear to show the “Meeting Room Settings”. However, the requirement was to be able to prevent double bookings of meeting rooms and this web part does it satisfactorily.

  • system sharepoint

    hi Dany Hoyek,
    I installed as guide but when run, appear error : “Object reference not set to an instance of an object. ”

    Please help .

    thanks so much !!!

    sorry, my english not well 🙁

  • Amber

    Hi Dany,

    Nice solution. Is there a way to automatically add this calender event to user’s outlook calendar?

    Thanks
    Amber

  • cibun swain

    Thanx Dany for this fantastic post, i have gone through .

    This post is near to my requirment.. But i am geting one issue, here is the code

    Microsoft.SharePoint.WebPartPages.ListViewWebPart listViewCalendarWp =
    (ListViewWebPart)SharePointWebPartHelper.FindWebPartByTitle(
    wpManager,
    CustomProperties.CalendarWpTitle);

    Here in ListviewCalenderWp i am geting null value so that Calender is not showing.. Waiting for your help Dany

  • Prashanth

    Hi Dany,

    Thanks for solution. I am getting error while SPView object updates. Message is “The file is not checked out. You must first check out this document before making changes. ”
    I am using SharePoint 2013. Thanks in advance.

  • Tola Dy

    I got this error on sharepoint 2013
    Cannot import the following key file: Key.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_2872610AB4442783 BookingRoom.ComponentModel
    pls help

    • luke

      Hi Tola
      That tutorial link.. on that tutorial just one modification do not chose that same key provided inside that folder containg the webpart files just delete it.. and also on visual studio exclude it from your project and when sign select a new one and create it own password

  • ar

    i have error “Object reference not set to an instance of an object” i don’t know whic web.config file in interpub or comon file to edit (add session)
    help please

    • DonL

      The Webpart settings calendar name is incorrect
      In the filter web part, edit the settings at the bottom when you open the edit web pat panel, where it asks for the Calendar Web Part Title, enter the exact title of your calendar so it knows what to apply the filter on.

  • Suhail Tandel

    I am trying to create this on SP2013, succesfully deployed the webpart but after adding the webpart on the page, on click of edit webpart i am not able to see the Meeting Room Settings category…Kindly provide your help.

  • Suhail Tandel

    I had used the Sharepoint 2013 feature for Booking Room, it is working fine on premises.
    I want to use this feature on Office 365, need your help how would i use this peice of feature on office 365…Kindly provide your help…