Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

Calendar - Disallow users from adding new item for day/time already

  Asked By: Abner Oneil         Date: Jun 28, 2009      Category: Sharepoint      Views: 518
 

We would like to use a SharePoint calendar for conference room
scheduling. Is there some code that I can add to prevent users from
adding a day/time that is already occupied? We want to prevent user
from double-booking the conference room.

Tagged:                    

 

4 Answers Found

 
Answer #1       Answered By: Rafael Willis          Answered On: Jun 28, 2009       

There's nothing out of the box. But it would be fairly easy to write an event
handler that would intercept the add  and cancel it if the conference  room was
already booked.

 
Answer #2       Answered By: Richard Davis          Answered On: Jun 28, 2009       

I'm getting the error "Expected catch or finally" on the third "}"
from the bottom on this code. Any ideas on what's wrong?

using System;
using Microsoft.SharePoint;

namespace WSS.Calendar.Events
{
class PreventDoubleBooking: SPItemEventReceiver
{
///<summary>
///This event is triggered when the user adds a new item
///<summary>
///<param name = "properties"></param>
public override void ItemAdding(SPItemEventProperties
properties)
{
//Our query string variable
string strQuery = null;

try
{
//Get the sharepoint  site instance
using (SPWeb oWebsite = new
SPSite(properties.SiteID).OpenWeb(properties.RelativeWebUrl))
{
//Get the collection of properties for the
Bookingitem
SPListItemCollection collItems = oWebsite.Lists
[properties.ListTitle].Items;

//Get the calendar  List that we will be querying
against
SPList calendar = oWebsite.Lists
[properties.ListId];
}
//Get the internal name of the fields we are querying.
//These are required for the CAML query
}
}
}
}

 
Answer #3       Answered By: Mason Davis          Answered On: Jun 28, 2009       

You can't use a Try/Catch block without specifying a catch. The code  should
look like this even if you aren't handling the possible exception:


using System;
using Microsoft.SharePoint;

namespace WSS.Calendar.Events
{
class PreventDoubleBooking : SPItemEventReceiver
{
///<summary>
///This event is triggered when the user adds a new item
///<summary>
///<param name = "properties"></param>
public override void ItemAdding(SPItemEventProperties properties)
{
//Our query string variable
string strQuery = null;

try
{
//Get the SharePoint site instance
using (SPWeb oWebsite = new
SPSite(properties.SiteID).OpenWeb(properties.RelativeWebUrl))
{
//Get the collection of properties for the Bookingitem
SPListItemCollection collItems =
oWebsite.Lists[properties.ListTitle].Items;

//Get the calendar  List that we will be querying against
SPList calendar = oWebsite.Lists[properties.ListId];
}
//Get the internal name of the fields we are querying.
//These are required for the CAML query
}
catch (Exception ex)
{

}
}
}
}

 
Answer #4       Answered By: Savannah Pena          Answered On: Jun 28, 2009       

...and if you're not handling the possible exception, PLEASE throw it back
to the calling layer:

catch (Exception ex)
{
throw(ex);
}

 


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].