Fixed font Subject: Re: Can't create new user property?
Author: Dmitry Streblechenko Date: 23 Nov 2009
References:
I think this is as self-explanatory as it gets: you already have a property
with the same name but a different property type.
Once you used a particular type for any given name, you are stuck with that
type.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Mark B" <none123@none.com> wrote in message
news:%23yPgaH$aKHA.5156@TK2MSFTNGP05.phx.gbl...
> VSTO C# Outlook 2007.
>
> Does anyone know why I am getting the following exception from the code
> below and what the solution is?
>
> "Exception while setting up user property:
> A custom field with this name but a different data type already exists.
> Enter a different name.
> Prop name = x-MYAPP-MyDate1
> Value=21/11/2009 3:01:30 a.m.
> Type = olDateTime"
>
>
> private void SetProperty(string propertyName, object value,
> Outlook.OlUserPropertyType propType)
> {
> try
> {
> //Create user property if does not exist
> if (mail.UserProperties[propertyName] == null)
> {
> mail.UserProperties.Add(propertyName, propType,
> true, Type.Missing);
> }
>
> //Set property value
> if (value != null)
> {
> mail.UserProperties[propertyName].Value = value;
> }
> //Delete the property if value was null
> else
> {
> mail.UserProperties[propertyName].Delete();
> }
> }
> catch (Exception e)
> {
> string msg = "Exception while setting up user property:\n"
> + e.Message + "\n"
> + "Prop name = " + propertyName + "\nValue=" +
> value.ToString() + "\nType = " + propType;
>
> MYAPP.LogMessage(msg);
>
> }
> }