سؤال

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.

هل كانت مفيدة؟

المحلول

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,
            ...
        });
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top