2 added 11 characters in body
source | link

You can bind the existing groups in your SPWebSPUser by something like:

SPGroupCollection webGroups = webcurrentUser.Groups;
checkboxlist.DataSource = webGroups;
checkboxlist.DataValueField = "ID";
checkboxlist.DataTextField = "Name";
checkboxlist.DataBind();

Then for giving permissions to particular document/list item.. Iterate through the selected groups by user and do something like:

//Break the role inheritance from List and remove any RoleAssignments
item.BreakRoleInheritance(false);
while (item.RoleAssignments.Count > 0)  
{ 
    item.RoleAssignments.Remove(0); 
}

foreach (ListItem li in checkboxlist.Items)
{
    if (li.Selected)
    {
        // Give permissions to a specific group
        SPGroup group = web.Groups.GetByID(Convert.ToInt32(li.Value));
        SPPrincipal principalGroup = group;
        SPRoleAssignment roleassignment_group = new SPRoleAssignment(group);
        SPRoleAssignment roleAssignment = workspace.RoleAssignments.GetAssignmentByPrincipal(principalGroup);

        item.RoleAssignments.Add(roleAssignment);
    }
}

You can bind the existing groups in your SPWeb by something like:

SPGroupCollection webGroups = web.Groups;
checkboxlist.DataSource = webGroups;
checkboxlist.DataValueField = "ID";
checkboxlist.DataTextField = "Name";
checkboxlist.DataBind();

Then for giving permissions to particular document/list item.. Iterate through the selected groups by user and do something like:

//Break the role inheritance from List and remove any RoleAssignments
item.BreakRoleInheritance(false);
while (item.RoleAssignments.Count > 0)  
{ 
    item.RoleAssignments.Remove(0); 
}

foreach (ListItem li in checkboxlist.Items)
{
    if (li.Selected)
    {
        // Give permissions to a specific group
        SPGroup group = web.Groups.GetByID(Convert.ToInt32(li.Value));
        SPPrincipal principalGroup = group;
        SPRoleAssignment roleassignment_group = new SPRoleAssignment(group);
        SPRoleAssignment roleAssignment = workspace.RoleAssignments.GetAssignmentByPrincipal(principalGroup);

        item.RoleAssignments.Add(roleAssignment);
    }
}

You can bind the existing groups in your SPUser by something like:

SPGroupCollection webGroups = currentUser.Groups;
checkboxlist.DataSource = webGroups;
checkboxlist.DataValueField = "ID";
checkboxlist.DataTextField = "Name";
checkboxlist.DataBind();

Then for giving permissions to particular document/list item.. Iterate through the selected groups by user and do something like:

//Break the role inheritance from List and remove any RoleAssignments
item.BreakRoleInheritance(false);
while (item.RoleAssignments.Count > 0)  
{ 
    item.RoleAssignments.Remove(0); 
}

foreach (ListItem li in checkboxlist.Items)
{
    if (li.Selected)
    {
        // Give permissions to a specific group
        SPGroup group = web.Groups.GetByID(Convert.ToInt32(li.Value));
        SPPrincipal principalGroup = group;
        SPRoleAssignment roleassignment_group = new SPRoleAssignment(group);
        SPRoleAssignment roleAssignment = workspace.RoleAssignments.GetAssignmentByPrincipal(principalGroup);

        item.RoleAssignments.Add(roleAssignment);
    }
}
1
source | link

You can bind the existing groups in your SPWeb by something like:

SPGroupCollection webGroups = web.Groups;
checkboxlist.DataSource = webGroups;
checkboxlist.DataValueField = "ID";
checkboxlist.DataTextField = "Name";
checkboxlist.DataBind();

Then for giving permissions to particular document/list item.. Iterate through the selected groups by user and do something like:

//Break the role inheritance from List and remove any RoleAssignments
item.BreakRoleInheritance(false);
while (item.RoleAssignments.Count > 0)  
{ 
    item.RoleAssignments.Remove(0); 
}

foreach (ListItem li in checkboxlist.Items)
{
    if (li.Selected)
    {
        // Give permissions to a specific group
        SPGroup group = web.Groups.GetByID(Convert.ToInt32(li.Value));
        SPPrincipal principalGroup = group;
        SPRoleAssignment roleassignment_group = new SPRoleAssignment(group);
        SPRoleAssignment roleAssignment = workspace.RoleAssignments.GetAssignmentByPrincipal(principalGroup);

        item.RoleAssignments.Add(roleAssignment);
    }
}