c# - User not found when adding an AD group to an SP group -
i trying run code suggested here: https://sharepoint.stackexchange.com/questions/72431/what-is-the-correct-way-to-add-an-ad-group-to-an-sp-group-with-permissions
the ensureuser line works, on web.users line, says user not found.
var membersgroup = web.sitegroups.getbyname(string.concat(web.title, " ", "members")); if (!string.isnullorempty(xlosgroupname)) { string xlosgroupnamewithdomain = string.concat(domainname, @"\", xlosgroupname); web.ensureuser(xlosgroupnamewithdomain); var adlosgroup = web.users[xlosgroupnamewithdomain]; membersgroup.users.add(adlosgroup.loginname, string.empty, adlosgroup.name, adlosgroup.notes); sproledefinition contribute = web.roledefinitions.getbytype(sproletype.contributor); sproleassignmentcollection roleassignments = web.roleassignments; sproleassignment roleassignment = new sproleassignment(xlosgroupnamewithdomain, string.empty, string.empty, string.empty); sproledefinitionbindingcollection roledefbindings = roleassignment.roledefinitionbindings; roledefbindings.add(contribute); roleassignments.add(roleassignment); }
you can try users web specified using following method: web.allusers
wish can you.
Comments
Post a Comment