惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Cyberwarzone
Cyberwarzone
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX
博客园_首页
博客园 - 聂微东
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
T
Tenable Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
A
About on SuperTechFans
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
D
Docker
P
Proofpoint News Feed

博客园 - Lordan

有sharepoint团队的公司 spgridview的过滤功能回调时发生错误~ moss web service的权限问题 LINQ to SharePoint 试用感受, 欢迎讨论~ 获取共享服务中用户配置的其它额外信息 发布一款天气预报webpart MOSS开发Solution Community Kit for SharePoint 利用资源文件实现多语言的系统 调试有JS的InfoPath 2003 发布一个域安全级别的无代码InfoPath表单作为文档库模版 (InfoPath 一) InfoPath表单容器XmlFormView 列出W3WP进程端口号的详细内容(小技巧) 在blog中添加attachments功能 (修改系统Control) 在blog中添加attachments功能 (利用SharePoint:AttachmentUpload ) (未解决) 显示表单页面的编辑模式 - Lordan - 博客园 利用SharePoint:DelegateControl部署自定义UserControl Flash + SharePoint WebService播放视频 (二) Flash + SharePoint WebService播放视频 (一)
文档库中文件夹的权限管理
Lordan · 2008-04-10 · via 博客园 - Lordan

需求:
      有一个文档库, 然后下面有很多的文件夹, 每个文件夹都有不同的权限系统, 因此当需要维护这些权限的时候,非常麻烦. 所以需要一个webpart来管理这些权限的内容.

分析:
     1. 用一个treeview列出文档库中的所有文件夹的内容.
     2. 使用一个gridview列出每个文件夹的权限, 点击不同的文件夹时候显示相应的权限.
     3. gridview有删除的功能.
     4. 可以添加uers到一个group, 把users/groups添加到某些文件夹中.

实现:

1. 创建了一个类显示权限的部分信息.:

    class Permission<T>
    
{
        
private T _strUsers;
        
private T _strPermissions;

        
public T Users
        
{
            
get return _strUsers; }
            
set { _strUsers = value; }
        }


        
public T Permissions
        
{
            
get return _strPermissions; }
            
set { _strPermissions = value; }
        }


        
public Permission()
        
{
        }


        
public Permission(T strUsers, T strPermissions)
        
{
            _strUsers 
= strUsers;
            _strPermissions 
= strPermissions;
        }

    }

2. 列出相关文件夹的权限:

    List<Permission<string>> GetItemsPermissions(string ItemName)
    
{
        List
<Permission<string>> subListP = new List<Permission<string>>();
        SPListItemCollection oSPListItems 
= currentList.Folders;
        
foreach (SPListItem oSPItem in oSPListItems)
        
{
            
if (oSPItem.Name == ItemName)
            
{
                SPRoleAssignmentCollection oSPRoles 
= oSPItem.RoleAssignments;
                subListP 
= GetRoles(oSPRoles);
            }

        }

        
return subListP;
    }



    List
<Permission<string>> GetRoles(SPRoleAssignmentCollection oSPRoles)
    
{
        List
<Permission<string>> resultList = new List<Permission<string>>();
        
foreach (SPRoleAssignment oSPRole in oSPRoles)
        
{
            SPRoleDefinitionBindingCollection oSPRoleDefinitions 
= oSPRole.RoleDefinitionBindings;
            
string strPermissionLevelName = string.Empty;
            
foreach (SPRoleDefinition oSPRoleDefinition in oSPRoleDefinitions)
            
{                                
                    strPermissionLevelName 
+= oSPRoleDefinition.Name + ",";
            }
                 
            strPermissionLevelName 
= strPermissionLevelName.Substring(0, strPermissionLevelName.Length - 1);
            Permission
<string> subPermission = new Permission<string>(oSPRole.Member.Name, strPermissionLevelName);
            resultList.Add(subPermission);
        }

        
return resultList;
    }

3. 删除权限:

    void DeleteRole(SPRoleAssignmentCollection oSPRoles, string strGroupName)
    
{
        
foreach (SPRoleAssignment oSPRole in oSPRoles)
        
{
            
if (oSPRole.Member.Name == strGroupName)
            
{
                SPPrincipal currentPrincipal 
= oSPRole.Member;
                oSPRoles.Remove(currentPrincipal);
                
break;
            }

        }

    }


    
// Delete permissions in selected folder.
    SPListItemCollection oSPListItems = myList.Folders;
    
foreach (SPListItem oSPItem in oSPListItems)
    
{
        
if (oSPItem.Name == strNodeName)
        
{
            
if (!oSPItem.HasUniqueRoleAssignments) oSPItem.BreakRoleInheritance(true);
            SPRoleAssignmentCollection oSPRoles 
= oSPItem.RoleAssignments;
            
foreach (string strGroup in ListGroups)
            
{
                DeleteRole(oSPRoles, strGroup);    
            }
                            
        }

    }

4.  添加user到group:

    int AddUserToGroup(string strUserName, string strGroupName, SPWeb myWeb)
    
{
        SPUser oSPUser 
= GetSPUser(strUserName, myWeb);
        
int GroupId = 0;
        
if (oSPUser != null)
        
{
            SPGroupCollection oSPGroups 
= myWeb.Groups;
            
foreach (SPGroup oSPGroup in oSPGroups)
            
{
                
if (oSPGroup.Name == strGroupName)
                
{
                    oSPGroup.AddUser(oSPUser);
                    GroupId 
= oSPGroup.ID;
                }

            }


        }

        
return GroupId;
    }

5.  添加users/groups到指定的文件夹中:

    // 获得选中的permissions
    List<string> ListPermissions = new List<string>();
    
foreach (ListItem Item in CheckBoxListPermissions.Items)
    
{
        
if (Item.Selected)
        
{
            ListPermissions.Add(Item.Text);
        }

    }

    
// 获得user/group
    if (currentUser != null)
    
{
        oSPRole 
= new SPRoleAssignment(currentUser);
    }

    
else if (currentGroup != null)
    
{
        oSPRole 
= new SPRoleAssignment(currentGroup);
    }


    
foreach (string strRoleDefinition in ListPermissions)
    
{
        oSPRole.RoleDefinitionBindings.Add(myWeb.RoleDefinitions[strRoleDefinition]);
    }

    
// 添加到指定的文件夹中
    SPListItemCollection oSPListItems = myList.Folders;
    
foreach (SPListItem oSPItem in oSPListItems)
    
{
        
if (!oSPItem.HasUniqueRoleAssignments) oSPItem.BreakRoleInheritance(true);
        
if (oSPItem.Name == strSelectNode)
        
{
            oSPItem.RoleAssignments.Add(oSPRole);
        }

    }

效果:
1.  显示权限的页面:

2. 添加users/groups 的页面.