public static void DeleteRoleDefinition(this RoleDefinitionCollection roleDefinitions, int id) { RoleDefinition roleDefinition = roleDefinitions.GetById(id); roleDefinition.DeleteObject(); roleDefinitions.Context.ExecuteQuery(); }
public static void DeleteRoleDefinition(this RoleDefinitionCollection roleDefinitions, string name) { RoleDefinition roleDefinition = roleDefinitions.GetByName(name); roleDefinition.DeleteObject(); roleDefinitions.Context.ExecuteQuery(); }
public void DCMRemoveRole(string rolename) { using (DocLibContext context = new DocLibContext(ServiceHelper.GetDocumentLibraryName())) { RoleDefinition roleDefinition = context.Web.RoleDefinitions.GetByName(rolename); roleDefinition.DeleteObject(); context.ExecuteQuery(); } }
/// <summary> /// Removes Permission level if exists in web context /// </summary> /// <param name="context">Client context</param> /// <param name="permissionLevelName">permission level name to remove</param> private static void RemovePermissionLevelIfExists(ClientContext context, string permissionLevelName) { try { Web web = context.Web; context.Load(web, items => items.RoleDefinitions); context.ExecuteQuery(); RoleDefinition role = web.RoleDefinitions.Where(item => item.Name == permissionLevelName).FirstOrDefault(); if (null != role) { context.Load(role); context.ExecuteQuery(); role.DeleteObject(); context.ExecuteQuery(); ErrorMessage.ShowMessage(string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["PermissionLevelRemoved"], permissionLevelName), ErrorMessage.MessageType.Notification); } } catch (Exception exception) { ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Removes Permission level if exists in web context /// </summary> /// <param name="context">Client context</param> /// <param name="permissionLevelName">Permission level name to remove</param> private static void RemovePermissionLevelIfExists(ClientContext context, string permissionLevelName) { Web web = context.Web; context.Load(web, items => items.RoleDefinitions); context.ExecuteQuery(); RoleDefinition role = web.RoleDefinitions.Where(item => item.Name == permissionLevelName).FirstOrDefault(); try { if (null != role) { context.Load(role); context.ExecuteQuery(); role.DeleteObject(); context.ExecuteQuery(); Console.WriteLine("Permission Level [{0}] Removed", permissionLevelName); } } catch (Exception exception) { Console.WriteLine(exception.Message); } }