0

I'm attempting to determine if a appointment item exists in a cached of online mailbox store. My code runs too slowly in the online store so I'm trying to hide the ribbon button for online stores.

 public bool Control_Visible_AptDates(Office.IRibbonControl control)
    {

        if (control.Context is Outlook.Inspector)
        {
            Outlook.Inspector inspector = (Outlook.Inspector)control.Context;
            if (inspector.CurrentItem is Outlook.AppointmentItem)
            {
                
                Outlook.AppointmentItem aptItem = inspector.CurrentItem as Outlook.AppointmentItem;

                if (true)
                {
                    //If item stored online return false
                }
                else
                {
                    //If item stored in cached Exchange mailbox store return true
                }

What is the best way to determine if the item is online or using cached Exchange mode?

Using Outlook Spy, I can see that there's a PR_STORE_OFFLINE which seems to be the property that I'm looking for. It exists in cached items only as far as I can tell.

bool offline = aptItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x6632000B");

Can this property be read using PropertyAccessor somehow or is Redemption required?

If Redemption is required can you provide a code snippet to get me started?

Thanks in advance!

related images- enter image description here enter image description here

Kevin Moore
  • 361
  • 4
  • 14

2 Answers2

1

PR_STORE_OFFLINE is only available on the IMsgStore object, not on the items. You can try to use Application.Session.ExchangeConnectionMode property - see https://learn.microsoft.com/en-us/office/vba/api/outlook.namespace.exchangeconnectionmode.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks for your reply Dmitry! I found a solution that seems to work for me. Let me know if you see any terrible issues :) – Kevin Moore Mar 11 '22 at 16:36
0

Found service method that seems to work for me. Should be able to rework it to check a mailitem as well, but I didn't test that scenario.

    bool IsItemCachedExchange(Outlook._AppointmentItem aptItem)
    {
        try
        {
            bool result = false;
            Outlook.Account account = aptItem.SendUsingAccount;
            if (account  != null)
            {
                Outlook.Store store = account.DeliveryStore;
                result = store.IsCachedExchange;
                Marshal.ReleaseComObject(store);
                Marshal.ReleaseComObject(account);
                return result;
            }
            else
            {
                result = false;
                return result;
            }
        }
        catch (Exception)
        {
            bool result = false;
            return result;
        }
    }

    public bool Control_Visible_AptDates(Office.IRibbonControl control)
    {
        try
        {
            if (control.Context is Outlook.Inspector)
            {
                Outlook.Inspector inspector = (Outlook.Inspector)control.Context;
                if (inspector.CurrentItem is Outlook.AppointmentItem)
                {
                    Outlook.AppointmentItem aptItem = inspector.CurrentItem;
                    bool isItemCachedLocal = IsItemCachedExchange(aptItem);

                    if (isItemCachedLocal == true)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }

                else
                {
                    return false;
                }
            }

            else
            {
                return false;
            }
        }
        catch (Exception)
        {
            return false;
        }
    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Kevin Moore
  • 361
  • 4
  • 14