Managing group roles

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can add a role to a group:

 

[C#]

 

using CMS.Community;

using CMS.SiteProvider;

using CMS.CMSHelper;

 

...

 

        string groupName = "customGroupName";

        string siteName = "CommunitySite";

 

        // Get group object 

        GroupInfo gi = GroupInfoProvider.GetGroupInfo(groupName, siteName);

 

        // If group exists

        if (gi != null)

        {

            // Create role object

            RoleInfo ri = new RoleInfo();

 

            // Set role properties

            ri.RoleName = "CustomGroupRole";

            ri.DisplayName = "Custom group role";

            ri.RoleGroupID = gi.GroupID;

            ri.SiteID = CMSContext.CurrentSiteID;

 

            // Save role to database

            RoleInfoProvider.SetRoleInfo(ri);

        }

 

The following sample code shows how you can add a group member to a group role:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

        string roleName = "CustomGroupRole";

        string siteName = "CorporateSite";

 

        // Get role object

        RoleInfo ri = RoleInfoProvider.GetRoleInfo(roleName, siteName);

 

        // Get user object

        UserInfo ui = UserInfoProvider.GetUserInfo("CustomGroupMember");

 

        // If role and user exist

        if ((ri != null) && (ui != null))

        {

            // Add user to role

            UserRoleInfoProvider.AddUserToRole(ui.UserID, ri.RoleID);

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_managing_group_roles.htm