Create Member Groups/Types & Properties Programatically
I have the need to create a specific Member Group/Type programatically and then add specific properties to it, this is for a package I'm creating and will be done via a usercontrol.
Anyone know of a package that does this? So I can check out how they went about it, or if you have done it a snippet example of code would be really helpful :)
For anyone interested, heres how I did - This basically creates a membertype and group with an alias of 'ForumUser', adds a tab called 'Content' to the member type and adds three properties to the Member type (1 x Textstring, 2 x Numeric)
Unfortunatly, I got stuck on the first line of code : CreateMemberType is not recognised ! I'm using Umbraco v6. I found out I could replace that line with :
Create Member Groups/Types & Properties Programatically
I have the need to create a specific Member Group/Type programatically and then add specific properties to it, this is for a package I'm creating and will be done via a usercontrol.
Anyone know of a package that does this? So I can check out how they went about it, or if you have done it a snippet example of code would be really helpful :)
anyone :S Guess I'll be digging in Umbraco source
Bump :S
For anyone interested, heres how I did - This basically creates a membertype and group with an alias of 'ForumUser', adds a tab called 'Content' to the member type and adds three properties to the Member type (1 x Textstring, 2 x Numeric)
const string memberTypeAlias = "ForumUser"; const string memberTypeName = "Forum User"; const string memberTabName = "Content"; const int textStringId = -88; const int numericId = -51; const string forumUserTwitterUrl = "forumUserTwitterUrl"; const string forumUserPosts = "forumUserPosts"; const string forumUserKarma = "forumUserKarma"; // First Create the MemberType var mt = CreateMemberType(memberTypeAlias, memberTypeName); // Now create the tab mt.AddVirtualTab(memberTabName); // Add the properties // 1) forumUserTwitterUrl > textString var dt = DataTypeDefinition.GetDataTypeDefinition(textStringId); mt.AddPropertyType(dt, forumUserTwitterUrl, "Twitter Username"); var prop = mt.getPropertyType(forumUserTwitterUrl); prop.Mandatory = false; prop.TabId = GetTabByCaption(mt, memberTabName).Id; prop.Save(); // 2) forumUserPosts > Numeric dt = DataTypeDefinition.GetDataTypeDefinition(numericId); mt.AddPropertyType(dt, forumUserPosts, "Users Post Amount"); prop = mt.getPropertyType(forumUserPosts); prop.Mandatory = false; prop.TabId = GetTabByCaption(mt, memberTabName).Id; prop.Save(); // 3) forumUserKarma > Numeric dt = DataTypeDefinition.GetDataTypeDefinition(numericId); mt.AddPropertyType(dt, forumUserKarma, "Users Karma Amount"); prop = mt.getPropertyType(forumUserKarma); prop.Mandatory = false; prop.TabId = GetTabByCaption(mt, memberTabName).Id; prop.Save(); // Lastly create the group MemberGroup.MakeNew(memberTypeAlias, User.GetUser(0));Hope it helps someone :)
Hi,
This is just what I was looking for.
Unfortunatly, I got stuck on the first line of code : CreateMemberType is not recognised ! I'm using Umbraco v6.
I found out I could replace that line with :
MemberType mt = MemberType.MakeNew(User.GetUser(0), memberTypeAlias);
I then got stuck on another unrecognised method GetTabByCaption :
But it could be replaced with :
prop.TabId= iTabID;
Where iTabID is instantiated when creating the new tab like so:
// Now create the tab
int iTabID = mt.AddVirtualTab(memberTabName);
Thanks Lee, it did help some1
Hope it helps some others 2 ...
Guys,
I had trouble too. (umbraco 6.2.1) But I finally got it like this:
Creating the membertype
Creating Properties in tabs + saving it
memberType.AddPropertyGroup("customtab");
var TextBoxDefinition = new DataTypeDefinition(-1, new Guid(Constants.PropertyEditors.Textbox));
memberType.AddPropertyType(new PropertyType(TextBoxDefinition) { Alias = "alias", Name = "Name", Description = "", Mandatory = false, SortOrder = 1 }, "customtab");
mts.Save(memberType);
The following functions couldnt be found (dont know whats going on here)
Hi take a look at http://www.charlesafford.com/blog-folder/umbraco-members-and-aspnet-membership-provider-1-1/
This should point you in the right direction :)
Anyone know the equivalent of the MemberType in Umbraco 7? Currently using Umbraco.Core.Models, but receive an error getting to the method MakeNew
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.