Sunday, December 27, 2015

How to programmatically get permissions for list using client object model SharePoint 2013

//Get the lists

ClientContext clientContext = new ClientContext(_siteurl);
clientContext.AuthenticationMode =ClientAuthenticationMode.Default;
clientContext.Credentials = new System.Net.NetworkCredential
(“peakfinders”, “password@1”, “peakfinders”);
Web oweb = clientContext.Web;

            List myList = 
oweb .Lists.GetByTitle("Employee");

            roles = 
oweb.LoadQuery(
            myList.RoleAssignments.Include(
            roleAssign => 
roleAssign.Member,
            
roleAssign=> roleAssign.RoleDefinitionBindings.Include(
            roleDefine => 
roleDefine.Name, // for each role def, include roleDef’s Name
            
roleDefine=> roleDefine.Description,
            
roleDefine=> roleDefine.RoleTypeKind,
            
roleDefine=> roleDefine.BasePermissions)));
            
clientContext.ExecuteQuery();

            Dictionary dicpermission= new Dictionary();

            foreach (RoleAssignment ra in roles)
            {
                var rdc = ra.RoleDefinitionBindings;
                string permission = string.Empty;
                foreach (var strrp in rdc)
                {
                    permission += 
strrp.Name.ToString() +","+ strrp.Description.ToString() +","+ strrp.RoleTypeKind.ToString()+","+ strrp.BasePermissions.ToString();                  
                }
                
dicpermission.Add(ra.Member.Title, permission);

No comments:

Post a Comment