How to add/remove attachments only for the Inspector

P

Pavel Rosoi

Hi
I have to develop an add-in for Outlook 2003 using VSTO in C#.
I want to use the Inspector associated to an MailItem in order to add some
attachments when the inspector is opened (NewInspector event) and remove
these attachments when it is closed, handling MailItem_Close event.
Which is the best approach?
Thank you
 
K

Ken Slovak - [MVP - Outlook]

I'd wait for the first Activate() event on the Inspector so that the
Inspector and CurrentItem are fully instantiated as strong object references
instead of the weak object references you get in NewInspector().

Then just use the usual Add() and Remove() methods to add and remove the
attachments.
 
P

Pavel Rosoi

Thank you
I use NewInspector event in order to have the Inspector reference.
Once the Activate() is fired, how do I obtain the Inspector reference? Via
Application.ActiveInspector()?
When I close the Inspector I have “Do you want to save changes?" window and
it seems to be correct because I still see the attachment and probably
Outlook detects the change. How do I prevent that? I use MailItem Close()
event for attachment removing.
Best regards
 
K

Ken Slovak - [MVP - Outlook]

I and many other people use Inspector wrappers in collections and
instantiate a wrapper class in NewInspector(). That way the wrapper class
knows its own Inspector and UI.

I have some samples of that at
http://www.slovaktech.com/outlook_2007_templates.htm. Those are for Outlook
2007 only. They illustrate how to handle all the things you're asking about.
 
P

Pavel Rosoi

Thank you for your answer.
I am able to add/remove attachments on the existing items, but I am
wondering if it is possible to directly control the Inspector form, bypassing
the item operations.
If I use the MailItem.Attachements Add/Remove I modify the
LastModificationTime property.

There is an API which allows to directly controlling the Inspector form
fields or any other way in order to put some supplementary information on the
Inspector form but without touching the item?
Best regards
 
K

Ken Slovak - [MVP - Outlook]

The Inspector is a window, a container. It's the Inspector.CurrentItem that
would have attachments, recipients, subject, etc. You must modify the item
if you want to play with its attachments, and any change to an item will of
course change the LastModificationTime property. You can't do what you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top