// Uncomment the method below to handle the event raised before a feature is deactivated. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite currentSite = properties.Feature.Parent as SPSite; SPWeb rootWeb = currentSite.RootWeb; SPUser currentUser = rootWeb.CurrentUser; SPGroupCollection groups = rootWeb.SiteGroups; groups.Remove("Trainers"); groups.Remove("Training Administrators"); groups.Remove("Students"); SPList registrationsList = rootWeb.Lists["Registrations"]; registrationsList.ResetRoleInheritance(); }
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { var web = (properties.Feature.Parent as SPSite).RootWeb; string groupName = "WOFHonorGroup"; try { SPGroupCollection collGroups = web.SiteGroups; collGroups.Remove(groupName); } catch { //Лог } }
public void DeleteGroup(string groupName) { try { using (SPWeb website = GetWebSite()) { SPGroupCollection sharepointGroups = website.SiteGroups; sharepointGroups.Remove(groupName); website.Update(); } } catch (Exception ex) { var log = new AppEventLog(AppException.ExceptionMessage(ex, "aGroupName", "ClsHelper")); log.WriteToLog(); } }
private void DeleteGroup(SPWeb web, string groupNames) { try { foreach (string groupName in groupNames.Split(';')) { if (IsExistGroup(web, groupName)) { web.AllowUnsafeUpdates = true; SPGroupCollection groupCol = web.SiteGroups; SPGroup group = web.SiteGroups.GetByName(groupNames); groupCol.Remove(group.Name); web.AllowUnsafeUpdates = false; } } } catch (Exception) { } }
/// <summary> /// Adds SharePoint group to SharePoint v3 site /// </summary> /// <param name="SiteURL">SharePoint v3 site URL</param> /// <param name="GroupName">Group to be added</param> /// <param name="GroupOwner">Group owner. If the user does not belong to site it will be added.</param> /// <param name="DefaultUser">Default group user. If the user does not belong to site it will be added.</param> /// <param name="OverwriteIfExists">If set, the group will be removed and created again, if it exists.</param> /// <param name="ResultText">The method returns log of operations performed.</param> /// <returns>true if the group is successfully added.</returns> public bool CreateUsersGroup(string siteURL, string groupName, CS4User groupOwner, CS4User defaultUser, bool overwriteIfExists, ref string resultText) { bool result = false; resultText = String.Format(TextResources.AttemptingToCreateGroup, groupName) + Environment.NewLine; SPSite site = null; SPWeb siteWeb = null; SPGroupCollection groups = null; try { site = new SPSite(siteURL); siteWeb = site.OpenWeb(); groups = siteWeb.SiteGroups; } catch (System.Exception ex) { resultText += TextResources.CantCreateGroup + ex.Message + System.Environment.NewLine; return(result); } SPUser user = null; bool createDefaultUser = false; try { user = siteWeb.SiteUsers[defaultUser.UserLoginWithDomain]; } catch { //user does not exist createDefaultUser = true; } SPMember owner = null; bool createGroupOwner = false; try { owner = siteWeb.SiteUsers[groupOwner.UserLoginWithDomain]; } catch { createGroupOwner = true; } try { if (createDefaultUser) { AddSiteUser(defaultUser); user = siteWeb.SiteUsers[defaultUser.UserLoginWithDomain]; } if (createGroupOwner) { AddSiteUser(groupOwner); owner = siteWeb.SiteUsers[groupOwner.UserLoginWithDomain]; } } catch (System.Exception ex) { resultText += TextResources.NoGroupOwnerOrDefaultUser + ex.Message + Environment.NewLine; return(result); } SPGroup group = null; bool groupExists = false; try { group = groups[groupName]; groupExists = true; resultText += TextResources.GroupExists + Environment.NewLine; } catch { //group does not exist } try { if (groupExists) { if (overwriteIfExists) { SPUserCollection groupUsers = group.Users; //emptying group users collection foreach (SPUser groupUser in groupUsers) { group.RemoveUser(groupUser); } groups.Remove(groupName); } else { result = true; return(result); } } groups.Add(groupName, owner, user, String.Empty); resultText += TextResources.GroupCreated + System.Environment.NewLine; result = true; } catch (System.Exception ex) { resultText += ex.Message; } return(result); }