Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to get a data type for User properties View modes: 
User avatar
Member
Member
lancetek - 10/7/2011 7:03:03 PM
   
How to get a data type for User properties
I'm using the API to update User information, but sometimes the source data is a different data type than the datatype of the User property being updated. How can I get the User Property Types?

For example, running the following:

UserInfo ui = UserInfoProvider.GetFullUserInfo("test");
ui.SetValue("joinDate", "not a date string");


Will throw an error about a mismatched type, since the User property "joinDate" is of Type DateTime.

IF a value already exists in "joinDate", I can do: ui["joinDate"].GetType() to get the Type, but if ui["joinDate"] is null, I can't.

I've tried looking for a property of the UserInfo object that contains this information but don't see anything obvious. I've also tried using Reflection, but a null value still returns null PropertyInfo...

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 10/10/2011 1:31:03 PM
   
RE:How to get a data type for User properties
It doesn't look like there is any way to do it using any exposed property or method or reflection. I can suggest a couple of ways to do it.

1. Since you have the word "Date" in the column name, you can check for that word in the column name and then parse the value into a datetime.

2. You could create a user for reference that has all of the data filled in with appropriate data types then use that user's properties to get the type of the data in each column.

Can you give us an example of what values might be passed as a "not a date string"?

You should have validation on your form or whatever you are using to process the data to check the data before you attempt to save it to the database.

User avatar
Member
Member
kentico_michal - 10/11/2011 3:30:31 AM
   
RE:How to get a data type for User properties
Hello,

You can also use the following code to get datatype of any field:


using CMS.FormEngine;
using CMS.SettingsProvider;
...

DataClassInfo dci = DataClassInfoProvider.GetDataClass("cms.user");
if (dci != null)
{
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
FormFieldInfo ffi = fi.GetFormField("UserIsExternal");
if (ffi != null)
{
FormFieldDataTypeEnum dataType = ffi.DataType;
}
}


Best regards,
Michal Legen

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 10/11/2011 8:40:29 AM
   
RE:How to get a data type for User properties
That's a good one Michal!

User avatar
Member
Member
lancetek - 10/11/2011 9:04:30 AM
   
RE:How to get a data type for User properties
THAT is exactly what I was looking for! Thanks!

Lance