• Login

Snippets

24

Check if a DNN TrueFalse (bool) profile property exists and if it doesn't create a new one

USE:

CheckProfilePropertyExistsTrueFalse("DoNotMail").ToString();

 

public string CheckProfilePropertyExistsTrueFalse(string propertyName)
{
	string value = null;

	ProfilePropertyDefinition ppd = ProfileController.GetPropertyDefinitionByName(this.PortalId, propertyName.ToString());
 //  ProfileController.AddPropertyDefinition()
	if (ppd == null)
	{
		// IT DOESN'T EXIST - -  CREATE IT

		DotNetNuke.Common.Lists.ListController objListCtrl = new DotNetNuke.Common.Lists.ListController();

		DotNetNuke.Entities.Profile.ProfilePropertyDefinition objDef = new DotNetNuke.Entities.Profile.ProfilePropertyDefinition();
		DotNetNuke.Entities.Profile.ProfileController objProfileController = new DotNetNuke.Entities.Profile.ProfileController();

		objDef.DataType = objListCtrl.GetListEntryInfo("DataType", "TrueFalse").EntryID;
		objDef.Length = 50;
		objDef.PortalId = this.PortalId;
		objDef.PropertyName = propertyName.ToString(); // This is your property Name
		objDef.Required = false;
		objDef.DefaultValue = "false";
		objDef.ViewOrder = -1;
		objDef.DefaultVisibility = DotNetNuke.Entities.Users.UserVisibilityMode.AdminOnly;
		objDef.Visible = true;
		objDef.PropertyCategory = "Donor";
		objDef.ReadOnly = false;
		
		DotNetNuke.Entities.Profile.ProfileController.AddPropertyDefinition(objDef);

		value = "Profile Property Created for " + propertyName.ToString() + "!";
	}
	else
	{
		value = "Profile Property Exists!";

	}
	return value;
}

Post Rating

Comments

There are currently no comments, be the first to post one!

Post Comment

Name (required)

Email (required)

Website