SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

Is it possible to check if the current account is a SharePoint administrator? The only way I can think of achieving this is by attempting to login to the https://tenant-admin.sharepoint.com and check if I get a 403.

I thought there might be a cleaner way of doing this? This if for SharePoint Online/Office 365

share|improve this question
up vote 3 down vote accepted

Try this:

using (var ctx = new ClientContext(webUri))
{
    var currentUser = ctx.Web.CurrentUser;
    ctx.Load(currentUser);
    ctx.ExecuteQuery();

    Console.WriteLine(currentUser.IsSiteAdmin);
}
share|improve this answer
    
what would I use for the webUri, to use the clientcontext would I not neet to authenticate against -admin.sharepoint url which would throw a 403 erro? – Webfort Mar 7 at 10:41
    
use your https://<domainname>.sharepoint.com url as webUri – Dikesh Gandhi Mar 7 at 10:57
    
Thanks, that looks like it works with the testing I have done. – Webfort Mar 7 at 11:19

REST API:

Use the below rest api to determine the current loggin user is site collection admin or not

https://<sharepointsiteurl>/_api/web/currentUser/issiteadmin

This returns the true or false value in xml format.

JS Format: Use the below SharePoint ecmaScript to identify the current user admin status,

function checkUserisSiteAdmin() {
    var clientContext = new SP.ClientContext();
    oUser = clientContext.get_web().get_currentUser();

    clientContext.load(oUser);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, function() {
            var userInfo = '';
            userInfo +='LoginName: '+ oUser.get_loginName() +', SiteAdmin: '+ oUser.get_isSiteAdmin();            
            alert(userInfo.toString());
        }),
        Function.createDelegate(this, function(sender, args) {           
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }));
}
ExecuteOrDelayUntilScriptLoaded(checkUserisSiteAdmin, "sp.js");
share|improve this answer

In CSOM, you can execute the following line of code:

_spPageContextInfo.isSiteAdmin;

Example:

alert(_spPageContextInfo.isSiteAdmin);
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.