zoukankan
html css js c++ java
深入浅出SharePoint——操作Item权限类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; namespace CR.SharePoint.HR.Common { public static class PermissionManager { //SPGroup group = web.Groups[0]; //SPUser user = web.Users[0]; //SPUser user2 = web.EnsureUser("mangaldas.mano"); //SPUser user3 = web.EnsureUser("Domain Users"); //SPPrincipal[] principals = { group, user, user2, user3 }; #region Adding Permissions to an item /// <summary> /// Set Permissions /// </summary> /// <param name="item">SPListItem</param> /// <param name="principals">IEnumerable</param> /// <param name="roleType">SPRoleType</param> public static void SetPermissions(SPListItem item, IEnumerable<SPPrincipal> principals, SPRoleType roleType) { if (item != null) { foreach (SPPrincipal principal in principals) { SPRoleDefinition roleDefinition = item.Web.RoleDefinitions.GetByType(roleType); SetPermissions(item, principal, roleDefinition); } } } /// <summary> /// Set Permissions /// </summary> /// <param name="item">SPListItem</param> /// <param name="user">SPUser</param> /// <param name="roleType">SPRoleType</param> public static void SetPermissions(SPListItem item, SPUser user, SPRoleType roleType) { if (item != null) { SPRoleDefinition roleDefinition = item.Web.RoleDefinitions.GetByType(roleType); SetPermissions(item, (SPPrincipal)user, roleDefinition); } } /// <summary> /// Set Permissions /// </summary> /// <param name="item">SPListItem</param> /// <param name="principal">SPPrincipal</param> /// <param name="roleType">SPRoleType</param> public static void SetPermissions(SPListItem item, SPPrincipal principal, SPRoleType roleType) { if (item != null) { SPRoleDefinition roleDefinition = item.Web.RoleDefinitions.GetByType(roleType); SetPermissions(item, principal, roleDefinition); } } /// <summary> /// Set Permissions /// </summary> /// <param name="item">SPListItem</param> /// <param name="user">SPUser</param> /// <param name="roleDefinition">SPRoleDefinition</param> public static void SetPermissions(SPListItem item, SPUser user, SPRoleDefinition roleDefinition) { if (item != null) { SetPermissions(item, (SPPrincipal)user, roleDefinition); } } /// <summary> /// Set Permissions /// </summary> /// <param name="item">SPListItem</param> /// <param name="principal">SPPrincipal</param> /// <param name="roleDefinition">SPRoleDefinition</param> public static void SetPermissions(SPListItem item, SPPrincipal principal, SPRoleDefinition roleDefinition) { if (item != null) { SPRoleAssignment roleAssignment = new SPRoleAssignment(principal); roleAssignment.RoleDefinitionBindings.Add(roleDefinition); item.RoleAssignments.Add(roleAssignment); } } #endregion #region Deleting all user Permissions from an item /// <summary> /// remove permisions /// </summary> /// <param name="item">SPListItem</param> /// <param name="user">SPUser</param> public static void RemovePermissions(SPListItem item, SPUser user) { if (item != null) { RemovePermissions(item, user as SPPrincipal); } } /// <summary> /// remove permisions /// </summary> /// <param name="item">SPListItem</param> /// <param name="principal">SPPrincipal</param> public static void RemovePermissions(SPListItem item, SPPrincipal principal) { if (item != null) { item.RoleAssignments.Remove(principal); item.SystemUpdate(); } } #endregion #region Removing specific roles from an item /// <summary> /// remove permission /// </summary> /// <param name="item">SPListItem</param> /// <param name="principal">SPPrincipal</param> /// <param name="roleDefinition">SPRoleDefinition</param> public static void RemovePermissionsSpecificRole(SPListItem item, SPPrincipal principal, SPRoleDefinition roleDefinition) { if (item != null) { SPRoleAssignment roleAssignment = item.RoleAssignments.GetAssignmentByPrincipal(principal); if (roleAssignment != null) { if (roleAssignment.RoleDefinitionBindings.Contains(roleDefinition)) { roleAssignment.RoleDefinitionBindings.Remove(roleDefinition); roleAssignment.Update(); } } } } /// <summary> /// remove permission /// </summary> /// <param name="item">SPListItem</param> /// <param name="principal">SPPrincipal</param> /// <param name="roleType">SPRoleType</param> public static void RemovePermissionsSpecificRole(SPListItem item, SPPrincipal principal, SPRoleType roleType) { if (item != null) { SPRoleDefinition roleDefinition = item.Web.RoleDefinitions.GetByType(roleType); RemovePermissionsSpecificRole(item, principal, roleDefinition); } } #endregion #region Updating or Modifying Permissions on an item /// <summary> /// modify Permissions /// </summary> /// <param name="item">SPListItem</param> /// <param name="principal">SPPrincipal</param> /// <param name="roleType">SPRoleType</param> public static void ChangePermissions(SPListItem item, SPPrincipal principal, SPRoleType roleType) { if (item != null) { SPRoleDefinition roleDefinition = item.Web.RoleDefinitions.GetByType(roleType); ChangePermissions(item, principal, roleDefinition); } } /// <summary> /// modify Permissions /// </summary> /// <param name="item">SPListItem</param> /// <param name="principal">SPPrincipal</param> /// <param name="roleDefinition">SPRoleDefinition</param> public static void ChangePermissions(SPListItem item, SPPrincipal principal, SPRoleDefinition roleDefinition) { SPRoleAssignment roleAssignment = item.RoleAssignments.GetAssignmentByPrincipal(principal); if (roleAssignment != null) { roleAssignment.RoleDefinitionBindings.RemoveAll(); roleAssignment.RoleDefinitionBindings.Add(roleDefinition); roleAssignment.Update(); } } #endregion } }
查看全文
相关阅读:
C# 课堂总结2-数据类型及转换方式
C# 课堂总结1-二进制转换
C++
C++ 程序设计语言
VS编译器问题总结
go 笔记
SIP协议 会话发起协议(二)
SIP协议 会话发起协议(一)
201707 一些好的文章
编程拾穗
原文地址:https://www.cnblogs.com/mingle/p/2308213.html
最新文章
单点登录SSO
Python正则表达式指南
python的json模块
python模块介绍- SocketServer 网络服务框架
python中threading模块详解(一)
python Queue模块
pandas入门
ConfigParser.MissingSectionHeaderError: File contains no section headers.
docker 部署 springboot项目和直接运行 jar 文件详细步骤
使用openlayers扩展插件ol-ext设置地图指定区域高亮
热门文章
TypeError: Cannot read property 'getAttribute' of undefined
设置nginx允许服务端跨域
nginx: [emerg] https protocol requires SSL support in /usr/local/nginx/conf/nginx.conf:50
数据库基础学习1-简介
c# 课堂总结6 --集合与结构体
c# 课堂总结7--函数
c#--foreach遍历的用法与split的用法
C# 课堂总结5-数组
C# 课堂总结4-类(常用的类)
C# 课堂总结3-语句
Copyright © 2011-2022 走看看