Jaa


How to set user permissions programmatically?

    1: SPSite site = null;
    2: SPWeb web = null;
    3: site = new SPSite("https://server:100/sites/DevSite/");
    4: web = site.OpenWeb();
    5: SPRoleAssignment roleAssignment = new SPRoleAssignment("domain\\user","alias@domain.com","Nishand","Simple Test For You!");
    6: SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
    7: roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
    8: web.RoleAssignments.Add(roleAssignment); 

 

Enjoy!!!