Pardon the crappy cut/paste job, but this is a method I have in one of my modules:
private void InitializeProfileProperties()
{
bool existsToken = false;
bool existsAlias = false;
ProfilePropertyDefinitionCollection col = DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionsByCategory(this.PortalId, "SW.AutoLogon");
foreach (ProfilePropertyDefinition exDef in col)
{
if (exDef.PropertyName == "SW.AL.Token")
existsAlias = true;
if (exDef.PropertyName == "SW.AL.Alias")
existsToken = true;
}
// first check to make sure we have the appropriate profile properties created
string propertyName = "SW.AL.Token";
ProfilePropertyDefinition def = null;
if (!existsToken)//def == null)
{
// create it
def = new ProfilePropertyDefinition();
def.DataType = 349; // datatype 349 is text
def.Length = 50;
def.PortalId = this.PortalId;
def.PropertyCategory = "SW.AutoLogon";
def.PropertyName = propertyName;
def.Required = false;
def.ViewOrder = 9999;
def.Visibility = UserVisibilityMode.AdminOnly;
def.Visible = false;
// save it
ProfileController.AddPropertyDefinition(def);
}
propertyName = "SW.AL.Alias";
if (!existsAlias)//def == null)
{
// create it
def = new ProfilePropertyDefinition();
def.DataType = 349; // datatype 349 is text
def.Length = 50;
def.PortalId = this.PortalId;
def.PropertyCategory = "SW.AutoLogon";
def.PropertyName = propertyName;
def.Required = false;
def.ViewOrder = 9999;
def.Visibility = UserVisibilityMode.AdminOnly;
def.Visible = false;
// save it
ProfileController.AddPropertyDefinition(def);
}
}