清理文档库中的文档角色
我一直在开发一个事件处理程序来清理 MOSS 中文档库新项目的 RolesAssignments。 我已经搜索了一种可以有效清理所有 RolesAssignments 的方法,尽管我发现接缝的最佳方法是循环 RolesAssignments 并逐个删除? 是否有其他方法来清理项目的所有 RolesAssignments?
我用于清理 RolesAssignments 的代码如下所示:
for (int i = ListItem.RoleAssignments.Count - 1; i >= 0; --i)
{
ListItem.RoleAssignments.Remove(i);
}
有人对如何处理这个问题有任何想法吗?
I have been developing an event handler to clean up the RolesAssignments of the new item of a document library in MOSS. I’ve searched for a method that could clean all the RolesAssignments efficiently, although the best way I found seams to be loop through the RolesAssignments and delete one by one? Is there another way to clean all the RolesAssignments for an item?
The code I’m using for cleaning the RolesAssignments look like this:
for (int i = ListItem.RoleAssignments.Count - 1; i >= 0; --i)
{
ListItem.RoleAssignments.Remove(i);
}
Does anyone have any ideas on how to deal with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在问题正文中给出的示例是执行此操作的最正确方法。 ResetRoleInheritance 和 BreakRoleInheritance 可能会满足您的需要,但这是它们执行的操作的副作用。 它们的目的不是删除 RoleAssignments,而是对角色继承进行操作。 来自 MSDN:
ResetRoleInheritance - “删除本地角色分配并恢复到父对象的角色分配。”
BreakRoleInheritance - “为以下对象创建唯一的角色分配物品,而不是从父母那里继承它们。”
如果角色继承已被破坏并且您正在使用特定的角色分配,则应使用问题中的循环删除它们。
The example you've given within the body of your question is the most correct way to do this. ResetRoleInheritance and BreakRoleInheritance may do what you need, but this is the side-effect of the operations they perform. Their purpose is not to remove RoleAssignments, but rather operate on role inheritance. From MSDN:
ResetRoleInheritance - "Removes the local role assignments and reverts to role assignments from the parent object."
BreakRoleInheritance - "Creates unique role assignments for the item rather than inheriting them from a parent."
If role inheritance is already broken and you are using specific role assignments, you should remove them using a loop as you have in your question.
我有答案,放置属性 SPListItem.BreakRoleInheritance(false) 来中断角色继承并删除角色分配。
I have the answer, put the propertie SPListItem.BreakRoleInheritance(false) to break the role inheritance and remove the role assignments.
重置角色继承怎么样? 这应该清除所有角色分配。
How about ResetRoleInheritance? This should clear out all of the RoleAssignments.