1

Can someone please suggest on how to fetch all the sitecollection administrators from SharePoint online(Office 365 SharePoint) using c# client object model.

Thank you

1
static void Main(string[] args)
{
    using (var clientContext = new ClientContext("http://aissp2013:90"))
    {
        Site site = clientContext.Site;                
        Web web = clientContext.Web;                
        UserCollection coll = web.SiteUsers;
        clientContext.Load(coll);
        clientContext.ExecuteQuery();
        foreach (User user in coll)
        {               
            if (user.IsSiteAdmin)
            {
                Console.WriteLine(user.LoginName);
            }                    
        }
    }

    Console.Read();
}
1

Get all sitecollection administrators using C# client object model :

using (var clientContext = new ClientContext("http://..."))
    {
        Site site = clientContext.Site;                
        Web web = clientContext.Web;                
        UserCollection coll = web.SiteUsers;
        clientContext.Load(coll);
        clientContext.ExecuteQuery();        
        foreach (User user in coll)
        {
           if (user.IsSiteAdmin)
           {
              // 'user' is SiteAdmin
           }
        }
     }
  • User is asking for C# Client Object model not Server Object Model. Above code uses Server Object Model. – Amit Mar 9 '15 at 8:53
  • 2
    Web.Users property is not present in client object model. – Nadeem Yousuf Mar 9 '15 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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