{sharepoint} SetPermission
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的更多相关文章
- BPM SharePoint解决方案分享
一.需求分析 SharePoint作为微软推出的协同类平台产品,为客户提供了门户.内容.文档.流程.社区.搜索.BI等一系列的解决方案,然而其流程功能由于设计理念差异,不能完全满足客户的需求,主要原因 ...
- Visual Studio 2013 添加一般应用程序(.ashx)文件到SharePoint项目
默认,在用vs2013开发SharePoint项目时,vs没有提供一般应用程序(.ashx)的项目模板,本文解决此问题. 以管理员身份启动vs2013,创建一个"SharePoint 201 ...
- 在 SharePoint Server 2016 本地环境中设置 OneDrive for Business
建议补丁 建议在sharepoint2016打上KB3127940补丁,补丁下载地址 https://support.microsoft.com/zh-cn/kb/3127940 当然不打,也可以用O ...
- SharePoint 2016 入门视频教程
之前一直有朋友让自己录一些SharePoint的入门视频,之前没有太多时间,一个巧合的机会收到CSDN学院的邮件,可以在CSDN上发布视频教程,自己就录了一些.说起录视频也是蛮辛苦的,每天下班吃完饭要 ...
- 如何使用本地账户"完整"安装 SharePoint Server 2010+解决“New-SPConfigurationDatabase : 无法连接到 SharePoint_Config 的 SQL Server 的数据 库 master。此数据库可能不存在,或当前用户没有连接权限。”
注:目前看到的解决本地账户完整安装SharePoint Server 2010的解决方案如下,但是,有但是的哦: 当我们选择了"完整"模式安装SharePointServer201 ...
- SharePoint 2016 必备组件离线安装介绍
前言 SharePoint 必备组件安装,一直以来都是SharePoint安装过程中的最大的坑,尤其是不能联网的服务器.博主在这里简单介绍一下离线安装过程,并附组件包下载以及安装命令,并且在windo ...
- SharePoint 2013 create workflow by SharePoint Designer 2013
这篇文章主要基于上一篇http://www.cnblogs.com/qindy/p/6242714.html的基础上,create a sample workflow by SharePoint De ...
- Install and Configure SharePoint 2013 Workflow
这篇文章主要briefly introduce the Install and configure SharePoint 2013 Workflow. Microsoft 推出了新的Workflow ...
- SharePoint 2013 configure and publish infopth
This article will simply descript how to configure and publish a InfoPath step by step. Note: To con ...
随机推荐
- C#中对 XML节点进行添加,删除,查找和删除操作
从网上整理所得 XMLDocument来操作XML比较简单,虽然有时效率不是很高.代码如下 已知有一个XML文件(bookstore.xml)如下: <?xml version="1. ...
- StarRTC , AndroidThings , 树莓派小车,公网环境,视频遥控(三)手机端
原文地址:http://blog.starrtc.com/?p=111 这篇来介绍一下整个项目的手机端部分.在上一篇里我们已经将sdk导入到项目中了,下边直接用即可. 1 登录StarRTC的服务跟小 ...
- BuddyPress创建组、查看成员信息等找不到页面
BuddyPress创建组.查看成员信息等找不到页面 http://aoxuangame.com/wordpress/groups/create/ http://aoxuangame.com/word ...
- 15 款优化表单的 jQuery 插件
网页上的表单提供给用户的一种交互的方式,用户输入数据,提交到服务器,等待后续的处理.这些表单在我们浏览的网页中随处可见,也容易被我们忽略. 比如,“联系我们”页面会提供一个表单给用户填写他们的信息和想 ...
- thinkphp 点击分类显示分类下的文章(完整)
控制器 <?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { public function index(){ $cate=M ...
- English Sentenses【no use】
1.Sorry if I might sound arrogant or offensive. 2.Any further question? 3.How dare you! 4.Try it if ...
- zebra/quagga
参考:http://blog.chinaunix.net/uid-25513153-id-212328.html 一.zebra安装 .编译安装 vim ./lib/zebra.h + 增加: #if ...
- Qt Creater中Clang-format的使用
起因在于习惯性的想格式化代码,发现Qt Creater默认居然是没有代码格式化的,只有一个缩进,搞毛线啊!!! 搜索了下,倒是很容易就搜到了,Qt Creater中有个插件:beautifier,在 ...
- ti8127下godb 开发
http://download.cnet.com/GoDB/3000-2212_4-10306159.html源码rdk https://github.com/vasa-c/go-db github ...
- Linux安装php运行环境
安装apache: yum install httpd httpd-devel 启动apache: /etc/init.d/httpd start 此时输入服务器的IP地址,应该看到apache的服 ...