A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Can't create new user property?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 23rd 09, 04:02 AM posted to microsoft.public.outlook.program_addins
Mark B[_2_]
external usenet poster
 
Posts: 93
Default Can't create new user property?

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

}
}

  #2  
Old November 23rd 09, 09:59 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Can't create new user property?

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" wrote in message
...
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);

}
}



  #3  
Old November 23rd 09, 10:38 PM posted to microsoft.public.outlook.program_addins
Mark B[_2_]
external usenet poster
 
Posts: 93
Default Can't create new user property?

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" wrote in message
...
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" wrote in message
...
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);

}
}




  #4  
Old November 23rd 09, 11:09 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Can't create new user property?

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)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Mark B" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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);

}
}






  #5  
Old November 23rd 09, 11:36 PM posted to microsoft.public.outlook.program_addins
Mark B[_2_]
external usenet poster
 
Posts: 93
Default Can't create new user property?

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" wrote in message
...
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)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Mark B" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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);

}
}






  #6  
Old November 23rd 09, 11:41 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Can't create new user property?

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)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Mark B" wrote in message
...
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" wrote in message
...
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)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Mark B" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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);

}
}








 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
User property for folder Sandeep K[_2_] Add-ins for Outlook 2 August 20th 09 09:16 PM
Displayname of User Property escamoteur Outlook and VBA 7 August 19th 09 09:46 PM
Displayname of User Property escamoteur Add-ins for Outlook 7 August 19th 09 09:46 PM
Get User Specified Folder Property Rob Outlook and VBA 4 March 5th 08 03:19 PM
Searching by User Property Sick Boy Outlook and VBA 1 May 23rd 07 06:47 PM


All times are GMT +1. The time now is 12:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.