Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Outlook 2007 Calendar Preview

, 20 Mar 2012
Rate this:
Please Sign up or sign in to vote.
A form region with a calendar preview for outlook 2007

Introduction 

One of the coolest features in Outlook 2010 is the calendar preview. Well, for those of us that are still using Outlook 2007, this is the Calendar Preview.

Background

Our company isn't planning to upgrade to Outlook 2010 any time soon. But still I wanted to have this feature on my Outlook. I have a lot of appointments and need to see my conflicts right away. Switching to the calendar to see the conflict and then coming back to the meeting request is such a waste of time. So I decided to write my own Calendar Preview control and place it on the meeting request. For this, I used a Form Region Control and a Calendar Control that I got from this guy. Thank you Ertan Tike.

Using the code

OK, has I said I am using a VSTO project for Outlook 2007 and a form region that is Adjoining? The code is very simple, again thanks to the great control from Ertan Tike that does all the work of showing a calendar like control. 

Let's start with the Form Region Factory part of the form region control. We need to declare what kind of message class we want to use. Because we are dealing with meeting, we need to use this message class: 

[Microsoft.Office.Tools.Outlook.FormRegionMessageClass("IPM.Schedule.Meeting")]

Next, let us look at the FormRegionInitializing event. Here we connect to the Outlook application and to the calendar folder.

private void AppFormRegionFactory_FormRegionInitializing(object sender,
             Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
{
    oApp = new Microsoft.Office.Interop.Outlook.Application();
    oNS = oApp.GetNamespace("MAPI");
    oCalendar = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
}

The next thing is the FormRegionShowing event:

private void AppFormRegion_FormRegionShowing(object sender, System.EventArgs e)
{
    try
    {
        //Get the calendar items
        Microsoft.Office.Interop.Outlook.Items oItems = 
           (Microsoft.Office.Interop.Outlook.Items)oCalendar.Items;  
        //Get the current item
        Microsoft.Office.Interop.Outlook.MeetingItem appM = 
           (Microsoft.Office.Interop.Outlook.MeetingItem)this.OutlookItem;
        //Get it has an Appointment
        Microsoft.Office.Interop.Outlook.AppointmentItem appItem = 
                         appM.GetAssociatedAppointment(false);
        //Set the date and time that we want to show (the Appointment date)          
        string startdate = appItem.Start.Date.ToShortDateString() + " 01:00"; 
        string enddate = appItem.Start.Date.ToShortDateString() + " 23:00";
        //Set the calendar control date
        dayView1.StartDate = appItem.Start.Date;
        dayView1.StartHour = appItem.Start.Hour-2;  //show from 2 hours before
        //Set the filter on our calendar items so we get only today meetings
        string filterTodayAppoints = "([Start]>'" + startdate + 
          "' And [End]<='" + enddate + "')";
        oItems.Sort("[Start]", false);
        oItems.IncludeRecurrences = true;
        myRestricted = oItems.Restrict(filterTodayAppoints);
        m_Appointments = new List<Appointment>();
        foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in myRestricted)
        {
            Appointment m_Appointment = new Appointment();
            m_Appointment.StartDate = item.Start;
            m_Appointment.EndDate = item.End;
            m_Appointment.Title = item.Subject+Environment.NewLine+item.Location+ 
                                  "; " + item.Organizer;
            if (item.Subject == appItem.Subject)
            {                    
                m_Appointment.BorderColor = Color.Orange;
            }
            //Add the to our list
            m_Appointments.Add(m_Appointment);
        }
    }
    catch (Exception ex)
    {
        return;
    }
}

All we got left to do is show our meeting on the calendar control:

private void dayView1_ResolveAppointments(object sender, ResolveAppointmentsEventArgs args)
{
    try
    {
        List<Appointment> m_Apps = new List<Appointment>();
        foreach (Appointment m_App in m_Appointments)
            m_Apps.Add(m_App);

        args.Appointments = m_Apps;
    }
    catch (Exception ex)
    {
        return;
    }
}

That's it. 

Points of Interest 

If you are not familiar with the Outlook form region, this is a good start, and I think it can be useful for any one that has as many appointments as I have. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ron Levy
Software Developer
Israel Israel
No Biography provided
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 20 Mar 2012
Article Copyright 2012 by Ron Levy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid