如何获取 SPList 中的所有文件夹,然后检查权限“Contribute”对于当前用户
我有一个这样的共享点列表:
List
---------Folder 1
-----------------Item 1
-----------------Item 2
---------Folder 2
-----------------Item 1
-----------------Item 2
---------Folder 3
-----------------Item 1
-----------------Item 2
如何获取
List
中的所有文件夹?之后检查当前用户是否对
文件夹 1
、文件夹 2
、文件夹 3
具有贡献
权限?
I have a sharepoint list like that:
List
---------Folder 1
-----------------Item 1
-----------------Item 2
---------Folder 2
-----------------Item 1
-----------------Item 2
---------Folder 3
-----------------Item 1
-----------------Item 2
How can I get all Folders in
List
?After that checking if current user has
Contribute
permission onFolder 1
,Folder 2
,Folder 3
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要获取列表中的文件夹列表,您可以使用
SPList
对象的Folders
属性:要检查给定用户是否对您需要获取的文件夹具有贡献权限与
SPFolder 关联的
检查给定用户的SPListItem
,RoleAssignment
并检查其 Contribute 的RoleDefinitionBindings
角色定义:使用示例
To get the list of folders of a list you can use the
Folders
property of theSPList
object:To check if a given user has Contribute permission on a folder you need to get the
SPListItem
associated with theSPFolder,
check for aRoleAssignment
of the given user and check itsRoleDefinitionBindings
for the Contribute Role Definition:Usage example
通过检查角色定义的成员资格来检查用户权限有点冒险。谁敢说角色定义不会被重命名,或者角色定义中包含的基本权限不会被修改。
如果目标主要是检查当前用户对安全对象的权限,那么我认为更好的方法是使用所需的权限掩码调用 SPSecurableObject(SPListItem、SPList、SPWeb 或 SPSite)的重载的DoesUserHavePermissions 方法之一。
Checking user permissions by checking their membership of role definitions is a bit risky. Who's to say that the role definition won't be renamed or that the base permissions included in the role definition won't have been modified.
If the goal is primarily to check the current user's permissions on a securable object then I think a better way is simply to call one of the overloaded DoesUserHavePermissions methods of the SPSecurableObject (SPListItem, SPList, SPWeb or SPSite) with the desired permission mask.