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 }
}

{sharepoint} SetPermission的更多相关文章

  1. BPM SharePoint解决方案分享

    一.需求分析 SharePoint作为微软推出的协同类平台产品,为客户提供了门户.内容.文档.流程.社区.搜索.BI等一系列的解决方案,然而其流程功能由于设计理念差异,不能完全满足客户的需求,主要原因 ...

  2. Visual Studio 2013 添加一般应用程序(.ashx)文件到SharePoint项目

    默认,在用vs2013开发SharePoint项目时,vs没有提供一般应用程序(.ashx)的项目模板,本文解决此问题. 以管理员身份启动vs2013,创建一个"SharePoint 201 ...

  3. 在 SharePoint Server 2016 本地环境中设置 OneDrive for Business

    建议补丁 建议在sharepoint2016打上KB3127940补丁,补丁下载地址 https://support.microsoft.com/zh-cn/kb/3127940 当然不打,也可以用O ...

  4. SharePoint 2016 入门视频教程

    之前一直有朋友让自己录一些SharePoint的入门视频,之前没有太多时间,一个巧合的机会收到CSDN学院的邮件,可以在CSDN上发布视频教程,自己就录了一些.说起录视频也是蛮辛苦的,每天下班吃完饭要 ...

  5. 如何使用本地账户"完整"安装 SharePoint Server 2010+解决“New-SPConfigurationDatabase : 无法连接到 SharePoint_Config 的 SQL Server 的数据 库 master。此数据库可能不存在,或当前用户没有连接权限。”

    注:目前看到的解决本地账户完整安装SharePoint Server 2010的解决方案如下,但是,有但是的哦: 当我们选择了"完整"模式安装SharePointServer201 ...

  6. SharePoint 2016 必备组件离线安装介绍

    前言 SharePoint 必备组件安装,一直以来都是SharePoint安装过程中的最大的坑,尤其是不能联网的服务器.博主在这里简单介绍一下离线安装过程,并附组件包下载以及安装命令,并且在windo ...

  7. SharePoint 2013 create workflow by SharePoint Designer 2013

    这篇文章主要基于上一篇http://www.cnblogs.com/qindy/p/6242714.html的基础上,create a sample workflow by SharePoint De ...

  8. Install and Configure SharePoint 2013 Workflow

    这篇文章主要briefly introduce the Install and configure SharePoint 2013 Workflow. Microsoft 推出了新的Workflow ...

  9. SharePoint 2013 configure and publish infopth

    This article will simply descript how to configure and publish a InfoPath step by step. Note: To con ...

随机推荐

  1. JavaScript(二):JavaScript语法及数据类型

    一.JavaScript语法 1.区分大小写ECMAScript中的一切,包括变量.函数名和操作符都是区分大小写的.例如:text和Text表示两种不同的变量.2.标识符所谓标识符,就是指变量.函数. ...

  2. js学习笔记34----自执行函数

    自执行函数的写法通常如下: 方式1: (function(){ *** 写事件处理代码 *** }()) 方式2: (function(){ *** 写事件处理代码 *** })() 方式3: !(f ...

  3. 如果你不知道这11款常见的Web应用程序框架 就说明你out了

    本文推荐了11款常见的Web应用程序框架,并列出了相关的学习资料和下载文档.如果对这些项目还不熟悉,就赶紧学起来吧~ Rails Rails是Ruby on Rails的简称,是一款开源的Web应用框 ...

  4. chrome 如何利用快捷键将光标移动到地址栏

    Windows: Ctrl + L 或 Alt + D 或 F6 Mac: Command + LLinux: Ctrl + L

  5. 转00600异常解决方案:ORA-00600: 内部错误代码, 参数: [19004], [], [], [], [], []

    <问题描述> ORACLE 10.1 OR 10.2中所有平台都存在该问题. <问题现象> 在进行多表关联复杂查询时出现 ORA-00600: 内部错误代码, 参数: [190 ...

  6. 【转】MFC 无边框窗口的拖动

    MFC中无边框窗口的拖动 void CXXXXDialog::OnLButtonDown(UINT nFlags, CPoint point) { PostMessage(WM_NCLBUTTONDO ...

  7. perl 中的哈希赋值

    在perl 中,通过代码动态的给哈希赋值,是最常见的应用场景,但是有些情况下,我们事先知道一些信息,当需要把这些信息存放进一个哈希的时候,直接给哈希赋值就好: 哈希的key不用说,就是一个字符串,关键 ...

  8. otunnel : 一个和lcx差不多的端口转发的工具

    项目地址 ooclab/otunnel 下载地址(内涵各大平台) http://dl.ooclab.com/otunnel/ otunnel 用法 前提: 1. 假设 server 的地址为 exam ...

  9. Spring-JDBC配置

    以C3P0连接池为例:由于C3P0是第三方,我们无法使用注解将其定义为bean,因此需要在applicationContext.xml中配置: <!-- 导入配置文件 --> <co ...

  10. require() 方法讲解

    require.config({ paths:{ "jquery":"jquery.min", "underscore":"und ...