Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment

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

share|improve this answer
add comment

You can write like this:

SPWeb theSite = SPContext.Current.Site.Url;
SPUser theUser = theSite.CurrentUser;
string strUserName = theUser.LoginName;
if(strUserName.IsSiteAdmin==true)
{
  //do what u want
}
else
{}

though I have not tested but try this.

share|improve this answer
add comment

Your Answer

 
discard

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