Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 779
Jon Avatar asked Jan 19 '26 20:01

Jon


1 Answers

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);
}
like image 89
Yorwing Avatar answered Jan 22 '26 09:01

Yorwing