如何基于SharePoint列表中的布尔字段设置项目级别权限 [英] How to set Item level Permission based on boolean field in SharePoint List

查看:65
本文介绍了如何基于SharePoint列表中的布尔字段设置项目级别权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有以下要求来编写ItemAdding甚至接收者(同步事件接收器)代码.

如果"IsConfidential"布尔值字段设置为true,则只有当前用户和经理"才能使用sharepoint组应该对该项目具有完全权限,否则应该继承该权限.

Kindlly分享您对此的想法吗?


谢谢&问候
迪帕克·乔汉(Deepak Chauhan)

I have following requirement to write the ItemAdding even reciever(synchronous event receiver) code.

If the  "IsConfidential" boolean field is set to true , then only current user and "Manager" sharepoint group shoud have full permission for the item, otherwise permission shoud be inherited.

Kindlly share your thoughts about this ?


Thanks & Regards
Deepak Chauhan

SharePoint 2010和2013和Office-365品牌和前端自定义,UI设计

SharePoint 2010 & 2013 and Office-365 Branding and Front End Customization, UI Design

推荐答案

在ItemAdding方法中,使用此

In the ItemAdding method, use this

if(IsConfidential) {
    var item = properties.ListItem;
    item.BreakRoleInheritance(false);
    var web = properties.Web;
    var user = web.CurrentUser;


    SPRoleDefinition spRole = web.RoleDefinitions["Contribute"];

    SPRoleAssignment roleAssignment = new SPRoleAssignment(user.LoginName, user.Email, user.Name, user.Notes);
    roleAssignment.RoleDefinitionBindings.Add(spRole);

    item.RoleAssignments.Add(roleAssignment);

 SPUser group = web.EnsureUser(strListItemSecurity_Group);
                   SPRoleAssignment roleassignment_group = new SPRoleAssignment(group);
                   roleassignment_group.RoleDefinitionBindings.Add(web.RoleDefinitions[strTHTListItemSecurity_Group_Role]);
                   item.RoleAssignments.Add(roleassignment_group);
}

尚未测试此代码.


这篇关于如何基于SharePoint列表中的布尔字段设置项目级别权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆