开发者

Getting RoleCollection as a string

开发者 https://www.devze.com 2023-01-31 05:59 出处:网络
We can get the roles of an SPUser by SPUser.Roles.But it will return SPRoleCollection. If we want to list all the roles we need to loop that.

We can get the roles of an SPUser by SPUser.Roles. But it will return SPRoleCollection. If we want to list all the roles we need to loop that.

For example an User has "Full Control","Read","Design" we need to loop the S开发者_JAVA技巧PRoleCollection object.

How can i get all the roles as a string with ',' separator?


As a rough guess, try:

var user = SPUser // However you get the user.

var roles = Sring.Join(",", (from r in user.Roles select r.Name).ToArray()));

Though if you're using SharePoint 2010, the Name property is obsolete apparently.

0

精彩评论

暂无评论...
验证码 换一张
取 消