My first issues by Customizing of Outlook with VSTO SE

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

These days I was experimenting with VSTO SE and Office 2007. By the way I migrated the MeetingService to the new Office version. During this action there were few interesting things, which just have to be published.

Issue 1: Using of Item properties

Imagine you are developing some Outlook AddIn. The user opens an appointment item and your code obtains the instance of the class _AppointmentItem. Now, for some reason you want to append some custom property to the appointment. To do that following code can be used:

_AppointmentItem appointment;

. . .

ItemProperty myProp = appointment.ItemProperties["MyProp"];

if(myProp == null)

myProp = appointment.ItemProperties.Add("MyProp",

Outlook.OlUserPropertyType.olText,false, Missing.Value);

This code was working for years. Now I noticed that sometimes by some properties it just does not work. It first checks for existence of the property MyProp. If the property does not exist (myProp) it will be created as property of appointment and not as property of its folder. This is done by using of argument false.

The interesting on this point is that if the property with the same name exists as folder's property the code above will not work at all.

Following line will return null, because the property is not property of the appointment item:

ItemProperty myProp = appointment.ItemProperties["MyProp"];

The problem is that the next line of code (appending of the property) will fail, because the property exists in the folder. Funny? J

Issue 2: Handling of the IRibbonControl.Context property

By using of custom ribbon on Office 2007, there is a handler method which handles the click on the button in your ribbon. This method looks like shown below:

public void OnToggleButton (Office.IRibbonControl control, bool isPressed)

It is very important to know that argument control has a Context property, which contains the instance of the outlook's Inspector object. That means following cast should work:

control.Context as Microsoft.Office.Interop.Outlook.InspectorClass

The good thing is that this cast works fine. The bad thing is that this cast sometimes does not work fine. I was looking everywhere to find out some solution until I tried to cast to the interface Microsoft.Office.Interop.Outlook.Inspector.

control.Context as Microsoft.Office.Interop.Outlook.Inspector

Now, the good thing is that the cast to interface Inspector works always. The bad thing is that I have to change my code (which was working for years). Another bad thing is that Outlook is still too complicate for programming. Anyhow, it looks more sexy J


Posted Dec 27 2006, 12:53 AM by Damir Dobric
Filed under:

Comments

Pelle wrote re: My first issues by Customizing of Outlook with VSTO SE
on 05-19-2008 13:10

Hav you got any further information about this? Matt Sthele suggested to read this for me - blogs.msdn.com/.../oom-net-part-2-outlook-item-leaks.aspx

developers.de is a .Net Community Blog powered by daenet GmbH.