Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Check User is in Admin Site Group

  Asked By: Payal    Date: Jan 24    Category: Sharepoint    Views: 2938

I'm trying to figure out a way to evaluate if a user is in the Administrator
site group to conditionally display tool parts. The code I've been trying to
use looks like this:

Dim thisSite As SPWeb = SPControl.GetContextWeb(Context)

Dim adminRole As SPRole = thisSite.Roles("Administrator")

Dim adminUsers As SPUserCollection = adminRole.Users

I get this error for all objects I create whenever I try to access the property

<error: an exception of type: {System.ArgumentException} occurred}>

After doing some research it looks like the user has to be a local administrator
on the machine for this code to run. Has anyone come across this before? Are
there any other approaches I could consider for evaluating if this user is a
site admin?



2 Answers Found

Answer #1    Answered By: Tom Pruitt     Answered On: Jan 24

Rather than attempting to enumerate the users in the role (which requires admin
privs as you have found), you can instead just use the SPWeb.UserIsSiteAdmin
(site collection admin) or SPWeb.UserIsWebAdmin (site admin).

Answer #2    Answered By: Sammie Lancaster     Answered On: Jan 24

Works great...thanks.....................

Didn't find what you were looking for? Find more on Check User is in Admin Site Group Or get search suggestion and latest updates.