`
PnP Core Component - Get Site Collection Administrators in SharePoint 2016
In this blog you will see how to get Site Collection Administrators in SharePoint 2016 with CSOM Extension Method using Console Application.
Code Snippet:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
- using OfficeDevPnP.Core;
-
- namespace SP2016PnPCoreComponentDemo
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- string siteUrl = "http://c7395723754/";
- string userName = "administrator";
- string password = "Mf165Nz2WV";
- string domain = "AD2012";
-
- OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
-
- try
- {
-
- using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))
- {
-
- List<OfficeDevPnP.Core.Entities.UserEntity> adminColl = ctx.Web.GetAdministrators();
- foreach (OfficeDevPnP.Core.Entities.UserEntity admin in adminColl)
- {
- Console.WriteLine("Title: " + admin.Title + " ---- LoginName: " + admin.LoginName + " ---- Email: " + admin.Email);
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error Message: " + ex.Message);
- }
- }
- }
- }