mmlschadegg
mmlschadegg

Reputation: 23

How to remove UserProperty with Outlook Interop?

I've run the following code to add a particular UserProperty of type olText:

mailItem.UserProperties.Add(Name: "MyProperty", Type: OlUserPropertyType.olText);

I decided I wanted to use integer for the type instead, and changed my code to:

mailItem.UserProperties.Add(Name: "MyProperty", Type: OlUserPropertyType.olInteger);

This, however, gives me a COMException stating that the property name already exists, but with a different type. I was not even aware that user properties would persist after shutting down my application. Now I can't seem to get rid of it!

I've tried as suggested here, but when I try to retrieve the UserProperty with mailItem.UserProperties["MyProperty"] I get null.

How can I get completely rid of the user properties that I've added? How do I even see them?

Upvotes: 0

Views: 210

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66276

You cannot keep in the same name and change the property type - once a named MAPI property is used with a particular type, the store provider remembers it.

You'd need to change the property name.

Upvotes: 1

Eugene Astafiev
Eugene Astafiev

Reputation: 49435

Use the UserProperties.Find method which locates and returns a UserProperty object for the requested property name, if it exists. Only if it is found you can call the Delete method to remove the existing declaration add a new one with a new property type.

Upvotes: 0

Related Questions