Action for selected attachment only

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

Action for selected attachment only
 
Thomas Bach


Guest


Hi,

i need some actions only for an selected attachment in a mail item. It seems, it?s very dificult to do this.

I found here in the forum some hints about the Event in Outlook 2007 'AttachmentContextMenuDisplay'. But i can?t find any sample how i can do this.

In the MSDN, there are some sample snippets, but they don?t work in the environment with Addd-In-Express.

Can you help me?

I can?t understand, that?s so difficult to find the selected Attachment and work with it.

Regards

Thomas
Posted 31 Jan, 2012 10:15:22 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hi Thomas,

Intercept that event using the Outlook Events component. The event handler is invoked when you right-click an attachment (only in Outlook 2007-2010). In the event handler, you cast the target parameter to Outlook.AttachmentSelection (Outlook 2007 and higher); this object represents selected attachments. You access individual attachments using AttachmentSelection[i] or AttachmentSelection.Item(i); this call returns an Outlook.Attachment object (a COM object that must be released) representing an attachment. When the context menu is closed, Outlook generates the ContextMenuClose event.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Feb, 2012 05:34:17 Top
Thomas Bach


Guest


Hi Andrei,

thanks for the answer. I?ve found some Posts with this solution.

But i am ashamed, i don?t know, how i can cast the target Parameter.

Can you help me with one line of code?

Regards

Thomas
Posted 01 Feb, 2012 06:12:41 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hi Thomas,

A raw sketch:

C#
Outlook.AttachmentSelection attachmentsSelected = target as Outlook.AttachmentSelection;


VB.NET
Dim attachmentsSelected as Outlook.AttachmentSelection  = CType(target, Outlook.AttachmentSelection)



Andrei Smolin
Add-in Express Team Leader
Posted 01 Feb, 2012 06:32:38 Top
Thomas Bach


Guest


Hi Andrei,

if i use

Dim attachmentsSelected as Outlook.AttachmentSelection = CType(target, Outlook.AttachmentSelection)

i got an error that AttachmentSelection is not available.

Regards

Thomas
Posted 01 Feb, 2012 07:05:52 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Interops for what Outlook version you are using? Do you have the following Imports statement:

Imports Outlook = Microsoft.Office.Interop.Outlook



Andrei Smolin
Add-in Express Team Leader
Posted 01 Feb, 2012 07:12:27 Top
Thomas Bach


Guest


Hi Andrei

I created the Project Version independent.

I haven?t the Statement

Regards

Thomas
Posted 01 Feb, 2012 07:19:56 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hi Thomas,

I suggest that you create a project for Outlook 2007 and test handling this event. Then, in case you really need to support earlier Outlook versions, you can use System.Type.InvokeMember to call required members of the AttachmentSelection interface in your real project.

If you prefer to go this route, you may want to read http://www.add-in-express.com/creating-addins-blog/2010/03/16/interop-assemblies-late-binding/


Andrei Smolin
Add-in Express Team Leader
Posted 01 Feb, 2012 08:29:58 Top
Thomas Bach


Guest


Hi Andrei,

thanks. I?ll try it.

Regards

Thomas
Posted 01 Feb, 2012 08:48:05 Top