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




Posts: 89
Joined: 2009-10-15
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
Thomas Bach
Posted 31 Jan, 2012 10:15:22 Top
Andrei Smolin


Add-in Express team


Posts: 14140
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.

Regards from Belarus (GMT+3),

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




Posts: 89
Joined: 2009-10-15
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
Thomas Bach
Posted 01 Feb, 2012 06:12:41 Top
Andrei Smolin


Add-in Express team


Posts: 14140
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)


Regards from Belarus (GMT+3),

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




Posts: 89
Joined: 2009-10-15
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
Thomas Bach
Posted 01 Feb, 2012 07:05:52 Top
Andrei Smolin


Add-in Express team


Posts: 14140
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


Regards from Belarus (GMT+3),

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




Posts: 89
Joined: 2009-10-15
Hi Andrei

I created the Project Version independent.

I havenīt the Statement

Regards

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


Add-in Express team


Posts: 14140
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 Supporting several Office versions in an add-in. Interop assemblies and late binding.

Regards from Belarus (GMT+3),

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




Posts: 89
Joined: 2009-10-15
Hi Andrei,

thanks. Iīll try it.

Regards

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