3

How to Create Profile Property Through Code in DNN (DotNetNuke)?

I tried this code:

DotNetNuke.Entities.Profile.ProfilePropertyDefinition def =
   DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Level");            

if (def != null)
{
    def.DataType = 10;
    def.Length = 40;                   
    def.PropertyValue = "Level";
    def.PropertyName = "Level";

    oUser.Profile.ProfileProperties.Add(def);
}

oUser.Profile.SetProfileProperty("Level", ddlLevel.SelectedItem.Text.ToString().Trim());
DotNetNuke.Entities.Profile.ProfileController.UpdateUserProfile(oUser, oUser.Profile.ProfileProperties);

But it won't work, please help me with suitable solution.

Ehsan
  • 831
  • 17
  • 27

1 Answers1

7

try out this code for adding Profile Property:

if (DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Level") == null)
{
    DotNetNuke.Entities.Profile.ProfileController.AddPropertyDefinition(
        new DotNetNuke.Entities.Profile.ProfilePropertyDefinition(this.PortalId)
        {
            PropertyName = "Name",
            DataType = 10,
            ...
        });
}
Ehsan
  • 831
  • 17
  • 27
  • My I ask , Does data type has always same ID for same type, Or We should find data type by other way. – adopilot Feb 22 '13 at 22:12
  • I'm not sure, but in DNN6 and DNN7 they are same. You can find them or many other lists in dbo.Lists. – Ehsan Feb 23 '13 at 10:26