zoukankan      html  css  js  c++  java
  • Sharepoint 权限

    Sharepoint权限中的关系:权限——角色 ——对象——关联

    //为角色赋予权限
    public void RoleAssignment(SPListItem item, SPPrincipal groupOrUser, SPRoleDefinition role)
            {
                item.Web.AllowUnsafeUpdates = true;
                if (!item.HasUniqueRoleAssignments)
                {
                    item.BreakRoleInheritance(true);//true则断开并继承原有权限,false则断开不继承原有权限
                }
                SPRoleAssignment assignment = new SPRoleAssignment(groupOrUser);
                assignment.RoleDefinitionBindings.Add(role);
                item.RoleAssignments.Add(assignment);
                item.Update();
                item.Web.AllowUnsafeUpdates = false;
            }
    
    //为权限级别分配权限基类:SPBasePermissions
            SPWeb oWebsite = SPContext.Current.Web
            SPRoleDefinitionCollection collRoles = oWebsite.RoleDefinitions;        //获取当前网站的权限集
                    SPRoleDefinition oRoleDefinition = collRoles["名称"];                  //权限集中的权限级别“名称”
                                                                                            //权限级别为网站操作中预先设定
                    oRoleDefinition.BasePermissions = SPBasePermissions.AddListItems |      //为权限级别分配权限积累
                        SPBasePermissions.BrowseDirectories |
                        SPBasePermissions.EditListItems |
                        SPBasePermissions.DeleteListItems |
                        SPBasePermissions.AddDelPrivateWebParts; ;
                    oWebsite.AllowUnsafeUpdates = true;
                    oRoleDefinition.Update();                                               //更新网站权限
                    oWebsite.AllowUnsafeUpdates = false;
    
    //完整分配权限方法
     public void ListItem_Permission(object sender, ClickedEventArgs e)
            {
                using (SPWeb oWebsite = SPContext.Current.Web)
                {
                    SPRoleDefinitionCollection collRoles = oWebsite.RoleDefinitions;
    
                    SPRoleDefinition oRoleDefinition = collRoles["test2"];
                    oRoleDefinition.BasePermissions = SPBasePermissions.AddListItems |
                        SPBasePermissions.BrowseDirectories |
                        SPBasePermissions.EditListItems |
                        SPBasePermissions.DeleteListItems |
                        SPBasePermissions.AddDelPrivateWebParts; ;
                    oWebsite.AllowUnsafeUpdates = true;
                    oRoleDefinition.Update();
                    oWebsite.AllowUnsafeUpdates = false;
                    SPPrincipal User = oWebsite.SiteGroups["权限名称"];                      //权限名称
                    RoleAssignment(oWebsite.Lists["列表名"].Items["Item名称"].Fields[""], User, oRoleDefinition);
                }
            }
  • 相关阅读:
    [leetcode]Valid Number
    [leetcode]Edit Distance
    [leetcode]Decode Ways
    [leetcode]Maximum Depth of Binary Tree
    [topcoder]BadNeighbors
    [topcoder]ZigZag
    [leetcode]Subsets II
    [leetcode]Merge Sorted Array
    [leetcode]Binary Tree Maximum Path Sum
    hdu 2964 Prime Bases(简单数学题)
  • 原文地址:https://www.cnblogs.com/renzh/p/SharepointPermissions.html
Copyright © 2011-2022 走看看