Exemplo n.º 1
0
 public static void LeaveGroup(this SPUser spUser, string groupName, SPWeb spWeb)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         using (SPSite site = new SPSite(spWeb.Site.ID))
         {
             using (SPWeb web = site.OpenWeb(spWeb.ID))
             {
                 SPGroup spGroup = web.SiteGroups[groupName];
                 if (spUser.InGroup(spGroup))
                 {
                     web.AllowUnsafeUpdates = true;
                     spGroup.RemoveUser(spUser);
                     web.AllowUnsafeUpdates = false;
                 }
             }
         }
     });
 }