SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a webpart for SharePoint in Visual Studio 2005. I am making use of a user control in this project. Now, I have to obtain the currently logged in user using JavaScript and check whether he is an administrator for the site collection.

If the user is supposed to be an administrator, then i have to show a div, otherwise I have to hide that div using JavaScript. How can i achieve this? Any insights provided on this would be of great use.

share|improve this question

You could try to play with Permissions Web Service and it's method GetPermissionsCollection. But if you are building a web part I really do not see why you have to use JavaScript, if you need to check user permissions I would suggest working with full SharePoint API directly from you web part code behind. Hiding and showing divs with JavaScript, based on user permissions is not very good practice.

For more details on SharePoint, and developing web parts check SPDevWiki.

share|improve this answer
Agreed, hiding/showing divs based on the user group membership is very insecure - a user could easily display content intended for an administrator. – James Love Aug 4 '10 at 10:37

I think the answer may be found here: at jQuery.SPServices discussion board

share|improve this answer

You can write like this:

SPWeb theSite = SPContext.Current.Site.Url;
SPUser theUser = theSite.CurrentUser;
string strUserName = theUser.LoginName;
  //do what u want

though I have not tested but try this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.