Sharepoint列表项权限修改

场景:删除列表项所有当前权限,替换为要求的权限(此处为 创建者可以修改,总监、组长可以查看)

 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim oweb As SPWeb = New SPSite("http://localhost:881/").OpenWeb("/wdb")
        Dim olist As SPList = oweb.Lists("话务中心客户电话记录表")
        Dim slist As SPList = oweb.Lists("客服列表")
        Dim GLname As String
        Dim oitm As SPListItem
        For Each oitm In olist.Items
            Dim sitm As SPListItem
            For Each sitm In slist.Items
                If InStr(oitm("客服"), sitm("姓名")) Then      '取组长名
                    GLname = sitm("GL")
                    Exit For
                End If
            Next
            If GLname = "" Then
                T1.AppendText(oitm.ID & "," & oitm("客服") & "找不到组长" & vbCrLf)
                Exit Sub
            End If

            Dim spp As SPRoleAssignment
            oitm.BreakRoleInheritance(True)                     '中断继承权限
            If oitm.RoleAssignments.Count > 0 Then              '清空当前权限
                For i = oitm.RoleAssignments.Count - 1 To 0 Step -1
                    oitm.RoleAssignments.Remove(i)
                Next
            End If
            For Each usr As SPUser In oweb.SiteUsers            '查询所有用户名
                If InStr(oitm("客服"), usr.Name) Then           '如果是当前创建者,加编辑权限
                    T1.AppendText(usr.LoginName)
                    spp = New SPRoleAssignment(usr)
                    spp.RoleDefinitionBindings.Add(oweb.RoleDefinitions("编辑_CantDel"))
                    oitm.RoleAssignments.Add(spp)
                    oitm.Update()
                    T1.AppendText(oitm.ID)
                    spp = Nothing
                ElseIf usr.Name = "总监" Or InStr(GLname, usr.Name) Then                '如果是总监或者组长,加查看权限
                    T1.AppendText(usr.LoginName)
                    spp = New SPRoleAssignment(usr)
                    spp.RoleDefinitionBindings.Add(oweb.RoleDefinitions("读取"))
                    oitm.RoleAssignments.Add(spp)
                    oitm.Update()
                    T1.AppendText(oitm.ID)
                    spp = Nothing
                End If
            Next
        Next
    End Sub


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Runnerchin/article/details/8820768
个人分类: 代码 运维相关
上一篇excel数据自动导入
下一篇读取系统"安全"日志中的失败登录尝试 + 添加攻击者IP到防火墙策略
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭