Wednesday, June 17, 2015

Add/Provide permission to user at site programatically

SPUser oUser=web.AllUsers[“domain/username”];
SPRole admins = web.Roles[“Full Control”];
admins.AddUser(oUser.LoginName, oUser.Email, siteRequestor.User.Name, “Notes”);
Or
web.AssociatedOwnerGroup.AddUser(oUser);
Or
SPRoleDefinition roleDefination;
SPRoleAssignment roleAssignment;
roleDefination = web.RoleDefinitions[“Full Control”];
roleAssignment = new SPRoleAssignment(oUser);
roleAssignment.RoleDefinitionBindings.Add(roleDefination);
web.RoleAssignments.Add(roleAssignment);

No comments:

Post a Comment