Add-in to Check for Double Resource Booking

I was working with a customer today that had an issue where one some occasions they were double-booking, triple booking or even booking up to 30 conference rooms for the same meeting. They were looking for a way to prevent this from happening because once booked and auto-accepted by the room, they were unable to “cancel” without an administrator. So, I wrote them some code that essentially does a check to make sure if they have more than one resource/room scheduled for a meeting it will prompt them to ask them if they are sure they want to do this. The trick – in this sample – is to put all the resources you care about into a text file called “MeetingRooms.txt” in the installation folder. It will read it into memory and then check to make sure no more than one is scheduled or it will stop the user from making the mistake.

You will need to start off creating a Visual Studio 2010 / Outlook 2010 / .NET 4.0 Add-in…Here is the code:

public partial class ThisAddIn
private void ThisAddIn_Startup(object sender, System.EventArgs e)
// attach to the Item Send Event
Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);

void Application_ItemSend(object Item, ref bool Cancel)
// try to cast to a Meeting Item
Outlook.MeetingItem meet = Item as Outlook.MeetingItem;
if (meet != null) // is it a meeting item - not null
// load the list of conference rooms from the install folder
List<string> rooms = new List<string>();
string path = System.Reflection.Assembly.GetExecutingAssembly().Location + "\\MeeingRooms.txt";
StreamReader sr = new StreamReader(path);
while (!sr.EndOfStream)
// save as lowercase -- we will compare this way

int cnt = 0;
// no loop through all the recipients
foreach (Outlook.Recipient r in meet.Recipients)
// if the recipient is in the List of rooms we count it
if (rooms.Contains(r.Name.ToLower()))

// now if we get more than one -- we have a problem
if (cnt > 1)
// notify the user they are about to send a meeting request
// that will book more than one room
DialogResult result = MessageBox.Show("You have more than one conference room on " +
"this meeting request. \n\n" +
"Are you sure you want to continue?", "Resource Conflict",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Hand);
// if the user hits cancel or no, we will
// cancel the send
if (result != DialogResult.Yes)
Cancel = true;
// otherwise, allow it
Cancel = false;

// exit for loop
Cancel = false;
Cancel = false;

You need the following using statements:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using System.IO;

4 thoughts on “Add-in to Check for Double Resource Booking”

  1. With any custom dialogs out QC found one annoying issues. If you close main outlook window, the Outlook looks like closed, but you dialog not.
    If you close that dialog, you will get a crash of Outlook.
    I didn’t find any workarround for that. If it would be possible to have a special event, like Outlook closing requested we might have ability to handle such case somehow.

    1. Interesting issue. The MessageBox should be modal so it should not allow you to close Outlook without closing the dialog. So, I am not sure what is happening. It may be that he dialog does not have a parent window handle so it is behaving independently. You might look at this overload for the MessageBox.Shho(): MessageBox.Show Method (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon) and set the IWin32Window in the first parameter to the Outlook window handle and see if that improves things.

      1. Sorry for delayed response, notification was buried with newer emails. Thank you for advice. I’ve tried it initially. It will prevent only to close Mail inspector, but Outlook controlled by Explorer. User still has possibility to close Explorer and there is no easy way to intercept this moment and let know when not to check.
        As a starting point I used this “Enforcing Business Rules in Outlook 2010”
        The code here:
        You may see that they are also using trick with assigning owner to dialog box.
        So how to reproduce the issue:
        1. Load the code
        2. Run it
        3. Try to create new contact item
        4. On Contact item add any data, for example Name
        5. Switch to Outlook Explorer window and press close
        6. You will see confirmation message from Outlook “Are you willing to save changes?”. Press Yes.
        7. Now you custom message box will appear.
        Press no.
        8. Inspector will appear either without title bar and you wouldn’t be able to close Outlook now or Outlook will crash.
        Sorry for localized interface I can’t switch it to English.
        So far we refused from intercepting events which prevent Inspectors from closing as our QA believe that such scenario users might reproduce frequently.

Leave a Reply