0
votes

I am creating an outlook AddIn in Visual Studio 2010.

I have two Outlook Calendars: 1) default exchange calendar and 2) Personal Time Tracking Calendar. I have a form region that displays account numbers to track my time to depending on the task.

What I would like to do is if the appointment is in my personal calendar, I would like to add the appointment also to my time tracking calendar.

I've tried this:

var outlook = new Application();
var appt = OutlookItem as AppointmentItem;

if (appt == null)
    return;

try
{

    if (!string.IsNullOrEmpty(txtbxCapNum.Text))
    {
        if (appt.UserProperties.Find(Constants.CAPITAL_NUMBER) == null)
        {
            appt.UserProperties.Add(Constants.CAPITAL_NUMBER, OlUserPropertyType.olText);
        }

        appt.UserProperties[Constants.CAPITAL_NUMBER].Value = txtbxCapNum.Text;
    }


    if (!(outlook.Application.ActiveExplorer().CurrentFolder).Name.Equals(Constants.TIME_TRACKING_CALENDAR) && chbxInclude.Checked)
    {

        GetTimeTrackingCalendar(outlook).Items.Add(appt);
    }

    appt.Save();
}
catch (System.Exception ex)
{
    MessageBox.Show(ex.Message);
}

Where GetTimeTrackingCalendar is defined as:

public static MAPIFolder GetTimeTrackingCalendar(Application outlook )
{
    MAPIFolder result = null;
    MAPIFolder calendars = (MAPIFolder)outlook.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
    for (int i = 1; i <= calendars.Folders.Count; i++)
    {
        if (calendars.Folders[i].Name != Constants.TIME_TRACKING_CALENDAR) continue;
        result = calendars.Folders[i];
        break;
    }
    return result;
}

However, the save method returns the following ambiguous error:

=============================================================================

Could not complete the operation. One or more parameter values are not valid.

Anyone know what parameter is not valid or even how to determine which parameter is invalid?

Thanks, BillN

1
You probably already know this, but a great tool for anyone working with programming Outlook interfaces is OutlookSpy, dimastr.com/outspy/home.htmRenniePet

1 Answers

0
votes

Loop through the Namerspace.Stores collection, find the store that you need and use Store.GetDefaultFolder(olFolderCalendar) to open the default CXalendar folder of that store.