Attachment context menu stopped working in 2016

Add-in Express™ Support Service
That's what is more important than anything else

Attachment context menu stopped working in 2016
 
Velja Radenkovic




Posts: 39
Joined: 2010-12-23
I've had this menu built in the following way:

AdxRibbonContextMenu added to add in and property ContextMenuNames set http://screencast.com/t/wtG20NDdl3zp
and property ribbons set to: OutlookMailRead;OutlookMailCompose;OutlookMeetingRequestRead;OutlookTask;OutlookResponseRead;OutlookPostRead;OutlookSharingRead;OutlookExplorer;OutlookMMSRead

There is button added to that context menu and Click event handler:


private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed)
{
    if (control.Context is Outlook.AttachmentSelection)
    {
        //Selection released in below routine
        List<Outlook.Attachment> clickedAttachments = new List<Outlook.Attachment>();
        Outlook.AttachmentSelection sel = control.Context as Outlook.AttachmentSelection;
        int count = sel.Count;
        for (int i = 1; i <= count; i++)
        {
            clickedAttachments.Add(sel[i]);
        }
        importAttachments(clickedAttachments);
    }       
}


This is working in outlook 2013 and 2010.

With outlook 2016, when you right click attachment in explorer preview pane, control.Context is not AttachmentSelection it is Outlook.Explorer. I tried to read AttachmentSelection property of Explorer https://msdn.microsoft.com/en-us/library/office/ff869315.aspx but its Count property is 0.

How can I get right clicked attachment?

I will inspect other places where I use this menu (inspector etc.) but this clearly doesn't work.
Posted 09 Nov, 2015 06:27:45 Top
Velja Radenkovic




Posts: 39
Joined: 2010-12-23
When you use context menu from inspector i.e. right click attachment in inspector situation looks better. Inspector.AttachmentSelection.Count is 1 so I guess I can work with that.

But as I stated above when right clicking attachment in Explorer its like this: http://screencast.com/t/mGyHOpJo5
Posted 09 Nov, 2015 06:34:07 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Velja,

Please check the code I published in https://www.add-in-express.com/forum/read.php?FID=5&TID=13337.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Nov, 2015 07:16:53 Top
Velja Radenkovic




Posts: 39
Joined: 2010-12-23
Andrei, I already have a code similar to yours and Explorer.AttachmentSelection.Count is 0 when it arrives to event handling procedure.

Look at first line of screenshot I already posted above. That's the debug watch on opening bracket of event handling routine.

http://screencast.com/t/mGyHOpJo5

It says: (control.Context is Outlook.Explorer) and now look at properties i.e. the one pointed to with red arrow. You see that count is 0. Your code doesnt deal with that.

I can't really try your code because I am using 2007 PIAs but I have this which should be pretty much same. Everything works except Explorer.AttachmentSelection.Count is ZERO.

else if (control.Context is Outlook.Explorer)
            {
                List<Outlook.Attachment> clickedAttachments = new List<Outlook.Attachment>();
                   
                object o = OutlookUtility.OLLateBoundPropertyGetHelper(control.Context, "AttachmentSelection");
                Outlook.AttachmentSelection sel = o as Outlook.AttachmentSelection;
                int count = sel.Count;
                for (int i = 1; i <= count; i++)
                {
                    clickedAttachments.Add(sel[i]);
                }
                importAttachments(clickedAttachments);
            }
Posted 09 Nov, 2015 08:02:58 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Velja Radenkovic writes:
... I am using 2007 PIAs ... Everything works except Explorer.AttachmentSelection.Count is ZERO.


Explorer.AttachmentSelection was introduced in Outlook 2010. This property is missing in the Outlook 2007 PIA. See also https://msdn.microsoft.com/en-us/library/office/ff869315%28v=office.15%29.aspx.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Nov, 2015 08:26:33 Top
Velja Radenkovic




Posts: 39
Joined: 2010-12-23
It can be fetched via reflection which is what I am doing. Please look at my screenshot. I am asking you 3 rd time too look at it.

http://screencast.com/t/mGyHOpJo5

My problem IS that Explorer.AttachmentSelection.Count is 0 which is what you can see on the top of SS.

My problem IS NOT that I don't know how to access that property.

I will put 2016 PIAs although I know the count will still be 0.
Posted 09 Nov, 2015 09:00:14 Top
Velja Radenkovic




Posts: 39
Joined: 2010-12-23
Andrei your code and office PIAs 2016 has same problem. Attachment selection count is 0.

Here is minimal test case (it uses your code and office 2016 PIAs): REMOVED

Here is video (skip to 2:00 . I had to manually register add in since Create setup project context menu item doesn't work):
REMOVED
Posted 09 Nov, 2015 09:54:10 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Velja,


[7936] !!! adxRibbonButton1_OnClick. context is Explorer
[7936] !!! adxRibbonButton1_OnClick. explorer != null
[7936] !!! adxRibbonButton1_OnClick. attachmentSelection.Count = 1


I suppose the Outlook build number is what makes the difference. I use Outlook 2016 16.0.6001.1034 32bit.


Andrei Smolin
Add-in Express Team Leader
Posted 10 Nov, 2015 03:12:56 Top
Velja Radenkovic




Posts: 39
Joined: 2010-12-23
I upgraded OL 2016 to last and Context is not Explorer anymore. It is Outlook.AttachmentSelection again. I have one more instance of OL 2016 in company that has this problem. I will ask for upgrade.
Posted 10 Nov, 2015 06:21:55 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Velja Radenkovic writes:
I upgraded OL 2016 to last and Context is not Explorer anymore.


Incredible. What is Outlook 2016 build number?


Andrei Smolin
Add-in Express Team Leader
Posted 10 Nov, 2015 06:27:48 Top