Can't create new user property?

Status
Not open for further replies.
M

Mark B

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);

}

}
 
D

Dmitry Streblechenko

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)

-

"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);

> }
> }
 
M

Mark B

The thing is I always get the error message:

'mail.UserProperties[propertyName]' is null

if I try to set its value though. Here's some immediate window results:

?mail.UserProperties[propertyName] == null

true

mail.UserProperties.Add(propertyName, propType, true, Type.Missing)

'mail.UserProperties.Add(propertyName, propType, true, Type.Missing)' threw

an exception of type 'System.Runtime.InteropServices.COMException'

base {System.Runtime.InteropServices.ExternalException}: {"A custom

field with this name but a different data type already exists. Enter a

different name."}

mail.UserProperties[propertyName].Value = value;

'mail.UserProperties[propertyName]' is null

?mail.UserProperties[propertyName].GetType()

'((object)(mail.UserProperties[propertyName]))' is null

?mail.UserProperties[propertyName].IsUserProperty

'mail.UserProperties[propertyName]' is null

mail.UserProperties[propertyName].Value = 0;

'mail.UserProperties[propertyName]' is null

"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message

news:O0HiUjIbKHA.5796@TK2MSFTNGP06.phx.gbl...
> 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)
>

>

>

> -
> "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);
>

>> }
> > }


>
 
D

Dmitry Streblechenko

It ios not just on a particular message - themapping is on thestore level,

plus you added the user property to teh folder props (thrird parameter =

true).

Dmitry Streblechenko (MVP)

-

"Mark B" <none123@none.com> wrote in message

news:%23fMKu2IbKHA.5544@TK2MSFTNGP02.phx.gbl...
> The thing is I always get the error message:

> 'mail.UserProperties[propertyName]' is null

> if I try to set its value though. Here's some immediate window results:

> ?mail.UserProperties[propertyName] == null
> true
> mail.UserProperties.Add(propertyName, propType, true, Type.Missing)
> 'mail.UserProperties.Add(propertyName, propType, true, Type.Missing)'
> threw an exception of type 'System.Runtime.InteropServices.COMException'
> base {System.Runtime.InteropServices.ExternalException}: {"A custom
> field with this name but a different data type already exists. Enter a
> different name."}
> mail.UserProperties[propertyName].Value = value;
> 'mail.UserProperties[propertyName]' is null
> ?mail.UserProperties[propertyName].GetType()
> '((object)(mail.UserProperties[propertyName]))' is null
> ?mail.UserProperties[propertyName].IsUserProperty
> 'mail.UserProperties[propertyName]' is null
> mail.UserProperties[propertyName].Value = 0;
> 'mail.UserProperties[propertyName]' is null

> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> news:O0HiUjIbKHA.5796@TK2MSFTNGP06.phx.gbl...
> >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)
> >

> >

> >

> > -
> > "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);
> >
>>> }
> >> }

>

>>

>
 
M

Mark B

My senior programmer whose work I am trying to debug decided that whenever

he wanted to add user property to a mail item, he would include the third

parameter as True. That is, adding the user-defined field to the folder as

well.

Using the Outlook GUI just now I have seen a few user fields that have

Yes/No type in the "User-Defined Fields in Inbox" but for the particular

item, the field type is Date/Time. So there is inconsistency there.

I'm am guessing to remedy the whole thing I'll go through and delete all

user defined fields in all folders -- Inbox, Sent Items etc.

Then I am thinking to amend his code below labeled "//Create user property

if does not exist", making the third parameter False instead of True.

Is there any downside to not having the user-defined fields mirrored in the

Folders?

Our code in other places does things like Advanced Search based on

user-defined field values.

I'd be interested to know best practice here -- it's for an Outlook 2007

VSTO C# Add-in for various different external clients.

"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message

news:OZUhNKJbKHA.1640@TK2MSFTNGP06.phx.gbl...
> It ios not just on a particular message - themapping is on thestore level,
> plus you added the user property to teh folder props (thrird parameter =
> true).

> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "Mark B" <none123@none.com> wrote in message
> news:%23fMKu2IbKHA.5544@TK2MSFTNGP02.phx.gbl...
> > The thing is I always get the error message:
>

>> 'mail.UserProperties[propertyName]' is null
>

>> if I try to set its value though. Here's some immediate window results:
>

>> ?mail.UserProperties[propertyName] == null
> > true
> > mail.UserProperties.Add(propertyName, propType, true, Type.Missing)
> > 'mail.UserProperties.Add(propertyName, propType, true, Type.Missing)'
> > threw an exception of type 'System.Runtime.InteropServices.COMException'
> > base {System.Runtime.InteropServices.ExternalException}: {"A custom
> > field with this name but a different data type already exists. Enter a
> > different name."}
> > mail.UserProperties[propertyName].Value = value;
> > 'mail.UserProperties[propertyName]' is null
> > ?mail.UserProperties[propertyName].GetType()
> > '((object)(mail.UserProperties[propertyName]))' is null
> > ?mail.UserProperties[propertyName].IsUserProperty
> > 'mail.UserProperties[propertyName]' is null
> > mail.UserProperties[propertyName].Value = 0;
> > 'mail.UserProperties[propertyName]' is null
>

>
>
>
>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> > news:O0HiUjIbKHA.5796@TK2MSFTNGP06.phx.gbl...
> >>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)
> >>

> >>

> >>

> >> -
> >> "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);
> >>
>>>> }
> >>> }
> >
>>>

> >


>
 
D

Dmitry Streblechenko

I doubt that will help, not least if you are using Exchange: on the low

level, user proeprties are stored as named MAPI properties. To get a

property tag, Outlook calls IMessage::GetIDsFromNames passing the GUID

(PS_PUBLIC_STRING for the user properties) and id (the property name in your

case, can also be an integer).

Once a particular combination of GUID/id is mapped to a tag (4 bytes int),

it will always be used for that store (mailbox). The very first time that

tag is used when setting a property, the store will remember the property

type (PT_BOOLEAN, PT_SYSTIME, etc).

You cannot make the store forget about a particular property, once it is

used, the type cannot be changed.

Dmitry Streblechenko (MVP)

-

"Mark B" <none123@none.com> wrote in message

news:uIBS8WJbKHA.2188@TK2MSFTNGP04.phx.gbl...
> My senior programmer whose work I am trying to debug decided that whenever
> he wanted to add user property to a mail item, he would include the third
> parameter as True. That is, adding the user-defined field to the folder as
> well.

> Using the Outlook GUI just now I have seen a few user fields that have
> Yes/No type in the "User-Defined Fields in Inbox" but for the particular
> item, the field type is Date/Time. So there is inconsistency there.

> I'm am guessing to remedy the whole thing I'll go through and delete all
> user defined fields in all folders -- Inbox, Sent Items etc.

> Then I am thinking to amend his code below labeled "//Create user
> property if does not exist", making the third parameter False instead of
> True.

> Is there any downside to not having the user-defined fields mirrored in
> the Folders?

> Our code in other places does things like Advanced Search based on
> user-defined field values.

> I'd be interested to know best practice here -- it's for an Outlook 2007
> VSTO C# Add-in for various different external clients.

> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> news:OZUhNKJbKHA.1640@TK2MSFTNGP06.phx.gbl...
> > It ios not just on a particular message - themapping is on thestore
> > level,
> > plus you added the user property to teh folder props (thrird parameter =
> > true).
>

>> > > Dmitry Streblechenko (MVP)
> >

> >

> >

> > -
> > "Mark B" <none123@none.com> wrote in message
> > news:%23fMKu2IbKHA.5544@TK2MSFTNGP02.phx.gbl...
> >> The thing is I always get the error message:
> >
>>> 'mail.UserProperties[propertyName]' is null
> >
>>> if I try to set its value though. Here's some immediate window results:
> >
>>> ?mail.UserProperties[propertyName] == null
> >> true
> >> mail.UserProperties.Add(propertyName, propType, true, Type.Missing)
> >> 'mail.UserProperties.Add(propertyName, propType, true, Type.Missing)'
> >> threw an exception of type 'System.Runtime.InteropServices.COMException'
> >> base {System.Runtime.InteropServices.ExternalException}: {"A custom
> >> field with this name but a different data type already exists. Enter a
> >> different name."}
> >> mail.UserProperties[propertyName].Value = value;
> >> 'mail.UserProperties[propertyName]' is null
> >> ?mail.UserProperties[propertyName].GetType()
> >> '((object)(mail.UserProperties[propertyName]))' is null
> >> ?mail.UserProperties[propertyName].IsUserProperty
> >> 'mail.UserProperties[propertyName]' is null
> >> mail.UserProperties[propertyName].Value = 0;
> >> 'mail.UserProperties[propertyName]' is null
> >
>>
>>
>>
>>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> >> news:O0HiUjIbKHA.5796@TK2MSFTNGP06.phx.gbl...
> >>>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)
> >>>

> >>>

> >>>

> >>> -
> >>> "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);
> >>>
>>>>> }
> >>>> }
> >>
>>>
>>>

>

>>

>
 
M

Mark B

Thanks very much for all your help.

I went ahead and manually deleted the user defined fields from the Inbox and

SentItems folders and the errors stopped.

I think I'll amend the code so that if he programmatically creates new user

fields, the 3rd parameter is false so the folders don't store the fields

too.

I can't see any downside to this. Please feel free to correct this view if

you think I would need folder-based user-defined fields.

"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message

news:u2KLBcJbKHA.5156@TK2MSFTNGP05.phx.gbl...
> I doubt that will help, not least if you are using Exchange: on the low
> level, user proeprties are stored as named MAPI properties. To get a
> property tag, Outlook calls IMessage::GetIDsFromNames passing the GUID
> (PS_PUBLIC_STRING for the user properties) and id (the property name in
> your case, can also be an integer).
> Once a particular combination of GUID/id is mapped to a tag (4 bytes int),
> it will always be used for that store (mailbox). The very first time that
> tag is used when setting a property, the store will remember the property
> type (PT_BOOLEAN, PT_SYSTIME, etc).
> You cannot make the store forget about a particular property, once it is
> used, the type cannot be changed.

> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "Mark B" <none123@none.com> wrote in message
> news:uIBS8WJbKHA.2188@TK2MSFTNGP04.phx.gbl...
> > My senior programmer whose work I am trying to debug decided that
> > whenever he wanted to add user property to a mail item, he would include
> > the third
> > parameter as True. That is, adding the user-defined field to the folder
> > as well.
>

>> Using the Outlook GUI just now I have seen a few user fields that have
> > Yes/No type in the "User-Defined Fields in Inbox" but for the particular
> > item, the field type is Date/Time. So there is inconsistency there.
>

>> I'm am guessing to remedy the whole thing I'll go through and delete all
> > user defined fields in all folders -- Inbox, Sent Items etc.
>

>> Then I am thinking to amend his code below labeled "//Create user
> > property if does not exist", making the third parameter False instead of
> > True.
>

>> Is there any downside to not having the user-defined fields mirrored in
> > the Folders?
>

>> Our code in other places does things like Advanced Search based on
> > user-defined field values.
>

>> I'd be interested to know best practice here -- it's for an Outlook 2007
> > VSTO C# Add-in for various different external clients.
>

>
>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> > news:OZUhNKJbKHA.1640@TK2MSFTNGP06.phx.gbl...
> >> It ios not just on a particular message - themapping is on thestore
> >> level,
> >> plus you added the user property to teh folder props (thrird parameter =
> >> true).
> >
>>> > >> Dmitry Streblechenko (MVP)
> >>

> >>

> >>

> >> -
> >> "Mark B" <none123@none.com> wrote in message
> >> news:%23fMKu2IbKHA.5544@TK2MSFTNGP02.phx.gbl...
> >>> The thing is I always get the error message:
> >>
>>>> 'mail.UserProperties[propertyName]' is null
> >>
>>>> if I try to set its value though. Here's some immediate window results:
> >>
>>>> ?mail.UserProperties[propertyName] == null
> >>> true
> >>> mail.UserProperties.Add(propertyName, propType, true, Type.Missing)
> >>> 'mail.UserProperties.Add(propertyName, propType, true, Type.Missing)'
> >>> threw an exception of type
> >>> 'System.Runtime.InteropServices.COMException'
> >>> base {System.Runtime.InteropServices.ExternalException}: {"A custom
> >>> field with this name but a different data type already exists. Enter a
> >>> different name."}
> >>> mail.UserProperties[propertyName].Value = value;
> >>> 'mail.UserProperties[propertyName]' is null
> >>> ?mail.UserProperties[propertyName].GetType()
> >>> '((object)(mail.UserProperties[propertyName]))' is null
> >>> ?mail.UserProperties[propertyName].IsUserProperty
> >>> 'mail.UserProperties[propertyName]' is null
> >>> mail.UserProperties[propertyName].Value = 0;
> >>> 'mail.UserProperties[propertyName]' is null
> >>
>>>
>>>
>>>
>>>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> >>> news:O0HiUjIbKHA.5796@TK2MSFTNGP06.phx.gbl...
> >>>>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)
> >>>>

> >>>>

> >>>>

> >>>> -
> >>>> "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);
> >>>>
>>>>>> }
> >>>>> }
> >>>
>>>>
>>>
>>
>>>

> >


>
 
D

Dmitry Streblechenko

Do you have a predefined set of user proeprties or do you create them

dynamically based on some criteria/

Keep in mind that tehre is a 65,000 limit on the number of named proeprty

mappings per store.

Once you reach that limit, no new named proeprty can be created, no matter

whether you add it to the folder fields or not.

Dmitry Streblechenko (MVP)

-

"Mark B" <none123@none.com> wrote in message

news:uTwnBaMbKHA.5156@TK2MSFTNGP05.phx.gbl...
> Thanks very much for all your help.

> I went ahead and manually deleted the user defined fields from the Inbox
> and SentItems folders and the errors stopped.

> I think I'll amend the code so that if he programmatically creates new
> user fields, the 3rd parameter is false so the folders don't store the
> fields too.

> I can't see any downside to this. Please feel free to correct this view if
> you think I would need folder-based user-defined fields.

> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> news:u2KLBcJbKHA.5156@TK2MSFTNGP05.phx.gbl...
> >I doubt that will help, not least if you are using Exchange: on the low
> >level, user proeprties are stored as named MAPI properties. To get a
> >property tag, Outlook calls IMessage::GetIDsFromNames passing the GUID
> >(PS_PUBLIC_STRING for the user properties) and id (the property name in
> >your case, can also be an integer).
> > Once a particular combination of GUID/id is mapped to a tag (4 bytes
> > int), it will always be used for that store (mailbox). The very first
> > time that tag is used when setting a property, the store will remember
> > the property type (PT_BOOLEAN, PT_SYSTIME, etc).
> > You cannot make the store forget about a particular property, once it is
> > used, the type cannot be changed.
>

>> > > Dmitry Streblechenko (MVP)
> >

> >

> >

> > -
> > "Mark B" <none123@none.com> wrote in message
> > news:uIBS8WJbKHA.2188@TK2MSFTNGP04.phx.gbl...
> >> My senior programmer whose work I am trying to debug decided that
> >> whenever he wanted to add user property to a mail item, he would include
> >> the third
> >> parameter as True. That is, adding the user-defined field to the folder
> >> as well.
> >
>>> Using the Outlook GUI just now I have seen a few user fields that have
> >> Yes/No type in the "User-Defined Fields in Inbox" but for the particular
> >> item, the field type is Date/Time. So there is inconsistency there.
> >
>>> I'm am guessing to remedy the whole thing I'll go through and delete all
> >> user defined fields in all folders -- Inbox, Sent Items etc.
> >
>>> Then I am thinking to amend his code below labeled "//Create user
> >> property if does not exist", making the third parameter False instead of
> >> True.
> >
>>> Is there any downside to not having the user-defined fields mirrored in
> >> the Folders?
> >
>>> Our code in other places does things like Advanced Search based on
> >> user-defined field values.
> >
>>> I'd be interested to know best practice here -- it's for an Outlook 2007
> >> VSTO C# Add-in for various different external clients.
> >
>>
>>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> >> news:OZUhNKJbKHA.1640@TK2MSFTNGP06.phx.gbl...
> >>> It ios not just on a particular message - themapping is on thestore
> >>> level,
> >>> plus you added the user property to teh folder props (thrird parameter
> >>> =
> >>> true).
> >>
>>>> > >>> Dmitry Streblechenko (MVP)
> >>>

> >>>

> >>>

> >>> -
> >>> "Mark B" <none123@none.com> wrote in message
> >>> news:%23fMKu2IbKHA.5544@TK2MSFTNGP02.phx.gbl...
> >>>> The thing is I always get the error message:
> >>>
>>>>> 'mail.UserProperties[propertyName]' is null
> >>>
>>>>> if I try to set its value though. Here's some immediate window
> >>>> results:
> >>>
>>>>> ?mail.UserProperties[propertyName] == null
> >>>> true
> >>>> mail.UserProperties.Add(propertyName, propType, true, Type.Missing)
> >>>> 'mail.UserProperties.Add(propertyName, propType, true, Type.Missing)'
> >>>> threw an exception of type
> >>>> 'System.Runtime.InteropServices.COMException'
> >>>> base {System.Runtime.InteropServices.ExternalException}: {"A custom
> >>>> field with this name but a different data type already exists. Enter a
> >>>> different name."}
> >>>> mail.UserProperties[propertyName].Value = value;
> >>>> 'mail.UserProperties[propertyName]' is null
> >>>> ?mail.UserProperties[propertyName].GetType()
> >>>> '((object)(mail.UserProperties[propertyName]))' is null
> >>>> ?mail.UserProperties[propertyName].IsUserProperty
> >>>> 'mail.UserProperties[propertyName]' is null
> >>>> mail.UserProperties[propertyName].Value = 0;
> >>>> 'mail.UserProperties[propertyName]' is null
> >>>
>>>>
>>>>
>>>>
>>>>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> >>>> news:O0HiUjIbKHA.5796@TK2MSFTNGP06.phx.gbl...
> >>>>>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)
> >>>>>

> >>>>>

> >>>>>

> >>>>> -
> >>>>> "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);
> >>>>>
>>>>>>> }
> >>>>>> }
> >>>>
>>>>>
>>>>
>>>
>>>
>>>

>

>>

>
 
M

Mark B

Thanks. We have a predefined number of 30.

The issue was that as the application was being developed, the head

developer changed the type of a few from Yes/No to Date/Time. Theoretically

it should all now be stable.

The app hasn't been released as yet so the issue was only on the development

machines.

"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message

news:uI63KEVbKHA.4780@TK2MSFTNGP04.phx.gbl...
> Do you have a predefined set of user proeprties or do you create them
> dynamically based on some criteria/
> Keep in mind that tehre is a 65,000 limit on the number of named proeprty
> mappings per store.
> Once you reach that limit, no new named proeprty can be created, no matter
> whether you add it to the folder fields or not.

> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "Mark B" <none123@none.com> wrote in message
> news:uTwnBaMbKHA.5156@TK2MSFTNGP05.phx.gbl...
> > Thanks very much for all your help.
>

>> I went ahead and manually deleted the user defined fields from the Inbox
> > and SentItems folders and the errors stopped.
>

>> I think I'll amend the code so that if he programmatically creates new
> > user fields, the 3rd parameter is false so the folders don't store the
> > fields too.
>

>> I can't see any downside to this. Please feel free to correct this view
> > if you think I would need folder-based user-defined fields.
>

>
>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> > news:u2KLBcJbKHA.5156@TK2MSFTNGP05.phx.gbl...
> >>I doubt that will help, not least if you are using Exchange: on the low
> >>level, user proeprties are stored as named MAPI properties. To get a
> >>property tag, Outlook calls IMessage::GetIDsFromNames passing the GUID
> >>(PS_PUBLIC_STRING for the user properties) and id (the property name in
> >>your case, can also be an integer).
> >> Once a particular combination of GUID/id is mapped to a tag (4 bytes
> >> int), it will always be used for that store (mailbox). The very first
> >> time that tag is used when setting a property, the store will remember
> >> the property type (PT_BOOLEAN, PT_SYSTIME, etc).
> >> You cannot make the store forget about a particular property, once it is
> >> used, the type cannot be changed.
> >
>>> > >> Dmitry Streblechenko (MVP)
> >>

> >>

> >>

> >> -
> >> "Mark B" <none123@none.com> wrote in message
> >> news:uIBS8WJbKHA.2188@TK2MSFTNGP04.phx.gbl...
> >>> My senior programmer whose work I am trying to debug decided that
> >>> whenever he wanted to add user property to a mail item, he would
> >>> include the third
> >>> parameter as True. That is, adding the user-defined field to the folder
> >>> as well.
> >>
>>>> Using the Outlook GUI just now I have seen a few user fields that have
> >>> Yes/No type in the "User-Defined Fields in Inbox" but for the
> >>> particular item, the field type is Date/Time. So there is inconsistency
> >>> there.
> >>
>>>> I'm am guessing to remedy the whole thing I'll go through and delete
> >>> all user defined fields in all folders -- Inbox, Sent Items etc.
> >>
>>>> Then I am thinking to amend his code below labeled "//Create user
> >>> property if does not exist", making the third parameter False instead
> >>> of True.
> >>
>>>> Is there any downside to not having the user-defined fields mirrored in
> >>> the Folders?
> >>
>>>> Our code in other places does things like Advanced Search based on
> >>> user-defined field values.
> >>
>>>> I'd be interested to know best practice here -- it's for an Outlook
> >>> 2007 VSTO C# Add-in for various different external clients.
> >>
>>>
>>>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> >>> news:OZUhNKJbKHA.1640@TK2MSFTNGP06.phx.gbl...
> >>>> It ios not just on a particular message - themapping is on thestore
> >>>> level,
> >>>> plus you added the user property to teh folder props (thrird parameter
> >>>> =
> >>>> true).
> >>>
>>>>> > >>>> Dmitry Streblechenko (MVP)
> >>>>

> >>>>

> >>>>

> >>>> -
> >>>> "Mark B" <none123@none.com> wrote in message
> >>>> news:%23fMKu2IbKHA.5544@TK2MSFTNGP02.phx.gbl...
> >>>>> The thing is I always get the error message:
> >>>>
>>>>>> 'mail.UserProperties[propertyName]' is null
> >>>>
>>>>>> if I try to set its value though. Here's some immediate window
> >>>>> results:
> >>>>
>>>>>> ?mail.UserProperties[propertyName] == null
> >>>>> true
> >>>>> mail.UserProperties.Add(propertyName, propType, true, Type.Missing)
> >>>>> 'mail.UserProperties.Add(propertyName, propType, true, Type.Missing)'
> >>>>> threw an exception of type
> >>>>> 'System.Runtime.InteropServices.COMException'
> >>>>> base {System.Runtime.InteropServices.ExternalException}: {"A
> >>>>> custom
> >>>>> field with this name but a different data type already exists. Enter
> >>>>> a
> >>>>> different name."}
> >>>>> mail.UserProperties[propertyName].Value = value;
> >>>>> 'mail.UserProperties[propertyName]' is null
> >>>>> ?mail.UserProperties[propertyName].GetType()
> >>>>> '((object)(mail.UserProperties[propertyName]))' is null
> >>>>> ?mail.UserProperties[propertyName].IsUserProperty
> >>>>> 'mail.UserProperties[propertyName]' is null
> >>>>> mail.UserProperties[propertyName].Value = 0;
> >>>>> 'mail.UserProperties[propertyName]' is null
> >>>>
>>>>>
>>>>>
>>>>>
>>>>>> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> >>>>> news:O0HiUjIbKHA.5796@TK2MSFTNGP06.phx.gbl...
> >>>>>>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)
> >>>>>>

> >>>>>>

> >>>>>>

> >>>>>> -
> >>>>>> "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);
> >>>>>>
>>>>>>>> }
> >>>>>>> }
> >>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>
>>
>>>

> >


>
 
C

Coffee guy

Hi Dmitry,

Can you point me to the specs where the 64k limit is explained. I'm in a

similar situation with user properties and need to understand better how that

works. If I create 15 properties on the folder (3rd parameter is true), does

that mean there are 15 mappings per AppointmentItem limit of approx. 4333

items? What if I set the 3rd param to false?

"Dmitry Streblechenko" wrote:


> Do you have a predefined set of user proeprties or do you create them
> dynamically based on some criteria/
> Keep in mind that tehre is a 65,000 limit on the number of named proeprty
> mappings per store.
> Once you reach that limit, no new named proeprty can be created, no matter
> whether you add it to the folder fields or not.

> > Dmitry Streblechenko (MVP)
>

>

>

> -
 
D

Dmitry Streblechenko

No, that AddToFolderFields parameter only updates the hidden message that

stores the custom properties definitions in teh parent folder. It does not

matter how many item you have in that folder.

You can look at that mesage with outlookSpy: go to that folder, click

IMAPIFolder on the OutlookSpy toolbar, go to the "Associated Contents" tab,

find the message with PR_MESSAGE_CLASS = IPC.MS.REN.USERFIELDS, open that

message, look at the PR_USERFIELDS property.

Dmitry Streblechenko (MVP)

-

"Coffee guy" <Coffeeguy> wrote in message

news:73963BBF-4F6E-4F05-9DD6-95462D2786E3@microsoft.com...
> Hi Dmitry,

> Can you point me to the specs where the 64k limit is explained. I'm in a
> similar situation with user properties and need to understand better how
> that
> works. If I create 15 properties on the folder (3rd parameter is true),
> does
> that mean there are 15 mappings per AppointmentItem limit of approx. 4333
> items? What if I set the 3rd param to false?

> "Dmitry Streblechenko" wrote:
>
> > Do you have a predefined set of user proeprties or do you create them
> > dynamically based on some criteria/
> > Keep in mind that tehre is a 65,000 limit on the number of named proeprty
> > mappings per store.
> > Once you reach that limit, no new named proeprty can be created, no
> > matter
> > whether you add it to the folder fields or not.
>

>> > > Dmitry Streblechenko (MVP)
> >

> >

> >

> > -

>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J How to create a drop down user defined field that will appear on an inbox view Outlook VBA and Custom Forms 8
I shared mailbox - can i create a rule (vba) for every user? Outlook VBA and Custom Forms 1
J How to create a user defined dropdown list field for a custom contact form Using Outlook 3
A Suggestions on ways to let apps create appointments in any user's calendar? Exchange Server Administration 0
S [outlook-users] Create contact group from other user's contacts Using Outlook 1
C How can I create a new MailItem inside a user folder? Outlook VBA and Custom Forms 4
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 0
Commodore Any way to create "from-only" account on Outlook 2021? Using Outlook 1
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
N Can't create NEW GROUP and add/remove a member from existing Group in Outlook Using Outlook 1
NVDon Create new Move To Folder list Outlook VBA and Custom Forms 0
C Create Meeting With Custom Form Outlook VBA and Custom Forms 2
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
G Create ordinal numbers for birthday Outlook VBA and Custom Forms 2
O Outlook 365 - How to create / copy a new contact from an existing one? Using Outlook 5
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10
A How to create fixed signatures for aliases that process through GMAIL? Outlook VBA and Custom Forms 0
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 2
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
B Can I create a local PST file for SPAM on a drive that is usually disconnected? Using Outlook 3
Chiba Create an appointment for all the members Outlook VBA and Custom Forms 1
S Create a clickable custom column field Outlook VBA and Custom Forms 0
O Create a custom contact form - questions before messing things up... Outlook VBA and Custom Forms 4
L automaticaly create a teams meeting with a sync Using Outlook 0
D Can Exchange Admin Center create a pst for users email/contacts/calendar? Exchange Server Administration 0
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
F How to create phone number as links in notes of Contacts Using Outlook 2
Nessa Can't create new appointment Using Outlook 1
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
C Create new Message with shared contacts & BCC'ing recipients Outlook VBA and Custom Forms 0
O Multiple email accounts - hesitate to create a new profile Using Outlook 3
G Can't create Folder Groups in Outlook 2013 Using Outlook 0
N Outlook rules don't create a copy for bcc'ed emails Using Outlook 3
F Delete/create/reset Exchange mailbox on Outlook.com Using Outlook.com accounts in Outlook 3
R Can not create folder to store specific emails in in Outlook for Mac Using Outlook 1
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
JackBlack What tools do you use to create the signature for email? Using Outlook 3
Rupert Dragwater How to create a new email with @outlook.com Using Outlook.com accounts in Outlook 32
F Should a new email account also create new contacts Using Outlook 2
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
R Outlook add-in to create new contact from an email. Using Outlook 0
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
Q Script to create a pst file for Archiving Using Outlook 1
Jennifer Murphy Can I create a Rule with Or'd conditions? Using Outlook 1
D Outlook macros to create meeting on shared calendar Outlook VBA and Custom Forms 10
G How do I create a custom pick list in VB for an outlook automated email? Outlook VBA and Custom Forms 1
L Create Custom Form Using Outlook 0
Diane Poremsky Create a Task when a Message is Flagged Using Outlook 0

Similar threads

Top