Detecting a user's group in SharePoint 2003

Listed below is a C# example of programmatically querying the group(s) a user belongs to on a SharePoint 2003 site:

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

private boolean IsContributor()
{
boolean bContributor = false;
SPWeb currentWeb = SPControl.GetContextWeb(this.Context);
SPRoleCollection currentRoles = currentWeb.CurrentUser.Roles;

foreach(SPRole myRole in currentRoles)
{
strRoles = myRole.Name.ToString();

if (strRoles == "Contributor")
{
bContributor = true;
break;
}
}

return bContributor;

}

Comments

Popular posts from this blog

Working with double quotes (") in VB.Net

Using VB Script to display part of an IP address

Object reference not set to an instance of an object when using HTMLEditorExtender