3
votes

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!

1
Shot in the dark ... the CustomProperty doesn't already exist in the delegate calendar(s), does it?Kevin Pope
Nope. All of the properties I'm adding are named specifically for this add-in. As a side note, even trying to add the properties manually within the Outlook form designer produces the same error. I'm starting to think it may be a permissions issue within Exchange. Though, I have given the test delegates full control of the mailbox and calendar folder, still get the same error.Jon
I'm hitting this same issue. Did you ever find a solution?David
I got around it by calling Save on the AppointmentItem before trying to add the UserProperty.David

1 Answers

4
votes

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);
}