Sunday, April 27, 2008

Get SPUser's for a SPRole in a Sharepoint Site

To add custom permission levels:

Site Settings > Advanced permissions > Settings > Permission Levels > Add a Permission Level

To access all users having a particular Permission Level.

public string GetEmailForRole(string RoleName)
{
const string NDA_SITENAME = http://Server:801/sites/SiteName;
StringBuilder EmailList = new StringBuilder();

SPSite NDASite = new SPSite(NDA_SITENAME);
SPWeb NDAWeb = NDASite.OpenWeb();

foreach (SPRole role in NDAWeb.Roles)
{
if (role.Name == RoleName )
{

SPUserCollection spusers = role.Users;
foreach (SPUser user in spusers)
{
if( user.Email != "")
{
EmailList.Append(user.Email);
EmailList.Append(";");
}
}
}
}

return EmailList.ToString();
}

1 comment:

Anonymous said...

I think we need to consider the ad security groups too....