Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Retrieve Role assignments of folder's and subfolder's files in sharepoint online using CSOM c#

$
0
0

Hi,

I want to get the user permissions of every document files in sharepoint online using csom c# so that I will be able to restore files with the correct user permissions.

Right now, I did it like this

List Lists = clientContext.Web.Lists.GetByTitle("Documents");
CamlQuery Query = CamlQuery.CreateAllItemsQuery(100);
ListItemCollection Items = Lists.GetItems(Query);
clientContext.Load(Items, item => item.Include(i => i.DisplayName, i => i.File, i => i.RoleAssignments.Include(roleAsg => roleAsg.Member, roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name, roleDef => roleDef.Description))));
clientContext.ExecuteQuery();
loginNames = new Dictionary<string, List<string>>();
foreach (ListItem litem in Items)
{
 List<string> roles = new List<string>();

 foreach (RoleAssignment role in litem.RoleAssignments)
 {
  roles.Add(role.Member.LoginName);
 }
 loginNames.Add(litem.File.Name, roles);
}

But this will retrieve the role assignments of files stored in Documents. But, along with files, sub folders will be there which also have files and again subfolders. I want role assignments of these files in nested subfolders also. How to get it.

Thanks,

Palak


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>