Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SPSecurity.RunWithElevatedPrivileges(delegate()
- {
- using(SPSite spSite = new SPSite(siteUrl))
- {
- using(SPWeb spWeb = spSite.OpenWeb())
- {
- spWeb.AllowUnsafeUpdates = true;
- for (int i =0; i < userRequest.Length; i++)
- {
- SPGroup spGroup = spWeb.SiteGroups[userRequest.GetValue(i).ToString() + "_Contribute"];
- spGroup.AddUser(selectedUser); //this works just fine
- }
- try
- {
- SPGroupCollection userCollection = selectedUser.Groups;
- foreach(SPGroup group in userCollection)
- {
- if(group.Name == spWeb.SiteGroups[userRequest.GetValue(i) + "_Read"].ToString())
- {
- group.RemoveUser(selectedUser); //this is where I get Access Denied and a catch in my method if the user is not a Site Admin when the code is ran
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.InnerException);
- }
- }
- }
- });
Add Comment
Please, Sign In to add comment