Jon
Jon

Reputation: 261

C# Outlook 2010 Addin - AppointmentItem.ItemProperties.Add Exception

I am working on an Outlook add-in that adds a Form Region to IPM.Appointment message classes. When this region is showed, it will first add a few properties to the AppointmentItem.

Outlook.AppointmentItem appItem;

private void FormRegion_FormRegionShowing(object sender, System.EventArgs e)
{
    try
    {
        appItem = (Outlook.AppointmentItem)this.OutlookItem;

        appItem.ItemProperties.Add("CustomProperty", Outlook.OlUserPropertyType.olText);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

This works fine on my calendar, but if I try to use the addin with a delegate calendar that I have either Editor or Owner access to, it throws the following exception:

System.UnauthorizedAccessException: You don't have appropriate permission to perform this operation.
  at Microsoft.Office.Interop.Outlook.Itemproperties.Add(String Name, OlUserPropertType Type, ObjectAddToFolderFields, Object DisplayFormat)
  at ThisAddin.FormRegion.FormRegion_FormRegionShowing(Ovject sender,EventArgs e)

Any and all help is appreciated!

Upvotes: 3

Views: 1451

Answers (1)

Yorwing
Yorwing

Reputation: 51

I encountered the same issue through UserProperties. For me the exception occurs only the first time I try to add the property. So to work around the issue I catch the exception and try again.

Outlook.UserProperties properties = appointmentItem.UserProperties;
Outlook.UserProperty property = null;
try
{
    property = properties.Add(propertyName, Outlook.OlUserPropertyType.olText);
}
catch (System.UnauthorizedAccessException exception)
{
    // the first time didn't work, try again once before giving up
    property = properties.Add(propertyName, Outlook.OlUserPropertyType.olText);
}

Upvotes: 5

Related Questions