View Single Post
  #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);

}
}






Ads