Second Stanza

April 28, 2008

Time Slot Reservations using SharePoint

Filed under: SharePoint — Tags: — dfbaskin @ 9:21 pm

I needed to set up a finite list of time slots where my SharePoint users can reserve at most one slot. (Specifcally, it’s a list of final exam time slots, one reservation per student.) I played around with the Room and Equipment Reservations templates, but they didn’t support this concept.

So after researching different options, it seemed to me that this could be implemented using a custom list that contains the following fields:

  • Description – The description of the time slot (I just used the ‘Title’ field).
  • Date and Time – The date and time of the start of the time slot.
  • Reserved By – The user that has reserved the time slot, which only contains a value when the time slot is actually reserved.

Reservations, then, must follow these rules:

  1. Only members of a single, specific SharePoint group may actually make reservations.
  2. The users making reservations may not otherwise edit the list (but the owner of the list may).
  3. A single user may only reserve one time slot.
  4. A user may not reserve a time slot for a different user.

The list definition contains the elements I need but there is extra work required to enforce these rules.

Item #1 is covered by the “Person or Group” SharePoint data type. The “Reserved By” field is set up to only allow the selection of a user from a specific SharePoint group.

Item #2 is covered by making the list read-only for the users making the reservations.

For Item #3, code must be added so that any other reservation made by a user must be removed before adding a new reservation.

For Item #4, the reservations editor should select the current user when making a resevation.

There are a number of ways to implement all of this, but I chose to create a web part. I was interested in displaying the time slots in a calendar view, with a “Reserve” link to make it as simple as possible for a user to reserve the slot. Therefore, the web part makes use of the SPCalendarView control, populating it with SPCalendarItem objects that are based on the items from the list discussed above. The link to the calendar item is customized to allow the web part to make the reservation when the link is clicked. Then, the list item page is displayed to show the new reservation (or even if no reservation was made due to the fact the time slot is already reserved or the user is not in the correct SharePoint group).

See the links below to view or download the source code.

There are many things that could be done to this source to make it more fully functional. For example:

  1. There is not a lot of feedback given to the user if a reservation is made or not. If a reservation cannot be made, the user should at least know why.
  2. The calendar view should be handled better so that it can actually switch between month, week, and day views.
  3. It would be nice for the calendar to automatically display the month that contains the first time slot, not just the current month. The work around I use is to add “?CalendarDate={month}%2F{day}%2F{year}” to the query string when adding a link to the reservation’s web part page.
  4. A user should be able to remove a reservation. Right now, a user with edit rights to the list must perform this function.
  5. The web part needs editable properties that can be used to define the name of the list, field names, and the SharePoint group name. Currently, these names are hard-coded into the web part.
  6. A user shouldn’t be able to reserve a time slot in the past.

Download / View Source Code
(View requires Microsoft Silverlight 1.0 and Internet Explorer)

Blog at