Get SharePoint Groups With Permissions Using CSOM

Get SharePoint Groups With Permissions Using CSOM

In this post, you will get SharePoint Groups With Permissions using CSOM. All SharePoint group has own permissions like Full Control, Contribute, Team members (Microsoft Project Web App), Project Managers (Microsoft Project Web App), Web Administrators (Microsoft Project Web App) etc.In my previous post, I wrote code for to Get SharePoint Group[AdSense-A]

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;
using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;
using PRCLNT = Microsoft.ProjectServer.Client;

namespace GetGroupWithPermissions_Using_CSOM
{
    class Program
    {
        static string UserName = "UserName";
        static string Passwords = "Password";
        public static string OnlinePWA = "PWAPath";
        static void Main(string[] args)
        {
            using (PRCLNT.ProjectContext ProjectCont = new PRCLNT.ProjectContext(OnlinePWA))//PWA Url
            {
                SecureString passWord4 = new SecureString();
                foreach (char c in Passwords.ToCharArray()) passWord4.AppendChar(c);
                ProjectCont.Credentials = new SharePointOnlineCredentials(UserName, passWord4);
                ProjectCont.Load(ProjectCont.Web);
                ProjectCont.ExecuteQuery();
                Web wsite = ProjectCont.Web;
                ProjectCont.Load(wsite, x => x.HasUniqueRoleAssignments, x => x.RoleAssignments.Include(RLASS=> roleAssigned.Member.Title,
                      RLASS=> RLASS.RoleDefinitionBindings.Include(
                      rlDef => rlDef.Name)));
                ProjectCont.ExecuteQuery();
                RoleAssignmentCollection roleASSC = wsite.RoleAssignments;
                if (roleASSC != null && roleASSC.Count != 0)
                {
                    Console.WriteLine("Unique Permissions: " + wsite.HasUniqueRoleAssignments);
                    foreach (RoleAssignment r in roleASSC)
                    {
                        Console.WriteLine("Group Name: " + r.Member.Title);
                        foreach (RoleDefinition rdf in r.RoleDefinitionBindings)
                            Console.WriteLine("Permission: " + rdf.Name);
                    }
                }
            }
        }
    }
}


 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!