Is there any efficient method to query unique permission list items under the list (both graph or CSOM)?












0















We have business request to scan the user permission across multiple OneDrive for Business, and we are asking if there is any efficient method to query unique permission list items under the list without one-by-one query list item? If yes, this will reduce unused requests to SharePoint Online if the item doesn't have unique permission.



Thank you.



Long










share|improve this question



























    0















    We have business request to scan the user permission across multiple OneDrive for Business, and we are asking if there is any efficient method to query unique permission list items under the list without one-by-one query list item? If yes, this will reduce unused requests to SharePoint Online if the item doesn't have unique permission.



    Thank you.



    Long










    share|improve this question

























      0












      0








      0








      We have business request to scan the user permission across multiple OneDrive for Business, and we are asking if there is any efficient method to query unique permission list items under the list without one-by-one query list item? If yes, this will reduce unused requests to SharePoint Online if the item doesn't have unique permission.



      Thank you.



      Long










      share|improve this question














      We have business request to scan the user permission across multiple OneDrive for Business, and we are asking if there is any efficient method to query unique permission list items under the list without one-by-one query list item? If yes, this will reduce unused requests to SharePoint Online if the item doesn't have unique permission.



      Thank you.



      Long







      microsoft-graph csom






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 27 '18 at 21:00









      LongLong

      83




      83
























          1 Answer
          1






          active

          oldest

          votes


















          0














          No directly such API in Graph now. But you can try the permissions API and then try and some filter.



          For CSOM:



          using (var ctx = new ClientContext(sitrUrl))
          {
          //ctx.Credentials = Your Credentials
          ctx.Load(ctx.Web, a => a.Lists);
          ctx.ExecuteQuery();
          List list = ctx.Web.Lists.GetByTitle("Documents");
          var listItems = list.GetItems(CamlQuery.CreateAllItemsQuery());
          //load all list items with default properties and HasUniqueRoleAssignments property
          ctx.Load(listItems, a => a.IncludeWithDefaultProperties(b => b.HasUniqueRoleAssignments));
          ctx.ExecuteQuery();
          foreach (var item in listItems)
          {
          Console.WriteLine("List item: " + item["FileRef"].ToString());
          if (item.HasUniqueRoleAssignments)
          {
          //load permissions if item has unique permission
          ctx.Load(item, a => a.RoleAssignments.Include(roleAsg => roleAsg.Member.LoginName,
          roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name,
          roleDef => roleDef.Description)));
          ctx.ExecuteQuery();
          foreach (var roleAsg in item.RoleAssignments)
          {
          Console.WriteLine("User/Group: " + roleAsg.Member.LoginName);
          List<string> roles = new List<string>();
          foreach (var role in roleAsg.RoleDefinitionBindings)
          {
          roles.Add(role.Description);
          }
          Console.WriteLine("Permissions: " + string.Join(",", roles.ToArray()));
          Console.WriteLine("----------------");
          }
          }
          else
          {
          Console.WriteLine("No unique permission found");
          }
          Console.WriteLine("###############");
          }
          }



          https://www.morgantechspace.com/2017/09/get-item-level-permissions-sharepoint-csom.html




          Or



          public static void HasUniquePermission()
          {
          OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

          string siteUrl = "https://******.sharepoint.com/sites/DeveloperSite/";
          string userName = "Sathish@********.onmicrosoft.com";
          string password = "********";

          using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
          {
          Web web = ctx.Web;
          ctx.Load(web.Lists);
          ctx.Load(web);

          ctx.ExecuteQueryRetry();

          List list = web.Lists.GetByTitle("D1");
          ctx.Load(list);
          ctx.Load(list, li => li.HasUniqueRoleAssignments);
          ctx.ExecuteQuery();

          System.Console.WriteLine(Convert.ToString(list.HasUniqueRoleAssignments));
          }
          }



          http://www.sharepointpals.com/post/SharePoint-Office-365-How-to-Get-the-Lists-with-Unique-Permissions-Programmatically-C-CSOM







          share|improve this answer
























          • Thank you Seiya, this is the solution if there is no direct api to do this.

            – Long
            Nov 30 '18 at 1:55











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53508076%2fis-there-any-efficient-method-to-query-unique-permission-list-items-under-the-li%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          No directly such API in Graph now. But you can try the permissions API and then try and some filter.



          For CSOM:



          using (var ctx = new ClientContext(sitrUrl))
          {
          //ctx.Credentials = Your Credentials
          ctx.Load(ctx.Web, a => a.Lists);
          ctx.ExecuteQuery();
          List list = ctx.Web.Lists.GetByTitle("Documents");
          var listItems = list.GetItems(CamlQuery.CreateAllItemsQuery());
          //load all list items with default properties and HasUniqueRoleAssignments property
          ctx.Load(listItems, a => a.IncludeWithDefaultProperties(b => b.HasUniqueRoleAssignments));
          ctx.ExecuteQuery();
          foreach (var item in listItems)
          {
          Console.WriteLine("List item: " + item["FileRef"].ToString());
          if (item.HasUniqueRoleAssignments)
          {
          //load permissions if item has unique permission
          ctx.Load(item, a => a.RoleAssignments.Include(roleAsg => roleAsg.Member.LoginName,
          roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name,
          roleDef => roleDef.Description)));
          ctx.ExecuteQuery();
          foreach (var roleAsg in item.RoleAssignments)
          {
          Console.WriteLine("User/Group: " + roleAsg.Member.LoginName);
          List<string> roles = new List<string>();
          foreach (var role in roleAsg.RoleDefinitionBindings)
          {
          roles.Add(role.Description);
          }
          Console.WriteLine("Permissions: " + string.Join(",", roles.ToArray()));
          Console.WriteLine("----------------");
          }
          }
          else
          {
          Console.WriteLine("No unique permission found");
          }
          Console.WriteLine("###############");
          }
          }



          https://www.morgantechspace.com/2017/09/get-item-level-permissions-sharepoint-csom.html




          Or



          public static void HasUniquePermission()
          {
          OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

          string siteUrl = "https://******.sharepoint.com/sites/DeveloperSite/";
          string userName = "Sathish@********.onmicrosoft.com";
          string password = "********";

          using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
          {
          Web web = ctx.Web;
          ctx.Load(web.Lists);
          ctx.Load(web);

          ctx.ExecuteQueryRetry();

          List list = web.Lists.GetByTitle("D1");
          ctx.Load(list);
          ctx.Load(list, li => li.HasUniqueRoleAssignments);
          ctx.ExecuteQuery();

          System.Console.WriteLine(Convert.ToString(list.HasUniqueRoleAssignments));
          }
          }



          http://www.sharepointpals.com/post/SharePoint-Office-365-How-to-Get-the-Lists-with-Unique-Permissions-Programmatically-C-CSOM







          share|improve this answer
























          • Thank you Seiya, this is the solution if there is no direct api to do this.

            – Long
            Nov 30 '18 at 1:55
















          0














          No directly such API in Graph now. But you can try the permissions API and then try and some filter.



          For CSOM:



          using (var ctx = new ClientContext(sitrUrl))
          {
          //ctx.Credentials = Your Credentials
          ctx.Load(ctx.Web, a => a.Lists);
          ctx.ExecuteQuery();
          List list = ctx.Web.Lists.GetByTitle("Documents");
          var listItems = list.GetItems(CamlQuery.CreateAllItemsQuery());
          //load all list items with default properties and HasUniqueRoleAssignments property
          ctx.Load(listItems, a => a.IncludeWithDefaultProperties(b => b.HasUniqueRoleAssignments));
          ctx.ExecuteQuery();
          foreach (var item in listItems)
          {
          Console.WriteLine("List item: " + item["FileRef"].ToString());
          if (item.HasUniqueRoleAssignments)
          {
          //load permissions if item has unique permission
          ctx.Load(item, a => a.RoleAssignments.Include(roleAsg => roleAsg.Member.LoginName,
          roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name,
          roleDef => roleDef.Description)));
          ctx.ExecuteQuery();
          foreach (var roleAsg in item.RoleAssignments)
          {
          Console.WriteLine("User/Group: " + roleAsg.Member.LoginName);
          List<string> roles = new List<string>();
          foreach (var role in roleAsg.RoleDefinitionBindings)
          {
          roles.Add(role.Description);
          }
          Console.WriteLine("Permissions: " + string.Join(",", roles.ToArray()));
          Console.WriteLine("----------------");
          }
          }
          else
          {
          Console.WriteLine("No unique permission found");
          }
          Console.WriteLine("###############");
          }
          }



          https://www.morgantechspace.com/2017/09/get-item-level-permissions-sharepoint-csom.html




          Or



          public static void HasUniquePermission()
          {
          OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

          string siteUrl = "https://******.sharepoint.com/sites/DeveloperSite/";
          string userName = "Sathish@********.onmicrosoft.com";
          string password = "********";

          using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
          {
          Web web = ctx.Web;
          ctx.Load(web.Lists);
          ctx.Load(web);

          ctx.ExecuteQueryRetry();

          List list = web.Lists.GetByTitle("D1");
          ctx.Load(list);
          ctx.Load(list, li => li.HasUniqueRoleAssignments);
          ctx.ExecuteQuery();

          System.Console.WriteLine(Convert.ToString(list.HasUniqueRoleAssignments));
          }
          }



          http://www.sharepointpals.com/post/SharePoint-Office-365-How-to-Get-the-Lists-with-Unique-Permissions-Programmatically-C-CSOM







          share|improve this answer
























          • Thank you Seiya, this is the solution if there is no direct api to do this.

            – Long
            Nov 30 '18 at 1:55














          0












          0








          0







          No directly such API in Graph now. But you can try the permissions API and then try and some filter.



          For CSOM:



          using (var ctx = new ClientContext(sitrUrl))
          {
          //ctx.Credentials = Your Credentials
          ctx.Load(ctx.Web, a => a.Lists);
          ctx.ExecuteQuery();
          List list = ctx.Web.Lists.GetByTitle("Documents");
          var listItems = list.GetItems(CamlQuery.CreateAllItemsQuery());
          //load all list items with default properties and HasUniqueRoleAssignments property
          ctx.Load(listItems, a => a.IncludeWithDefaultProperties(b => b.HasUniqueRoleAssignments));
          ctx.ExecuteQuery();
          foreach (var item in listItems)
          {
          Console.WriteLine("List item: " + item["FileRef"].ToString());
          if (item.HasUniqueRoleAssignments)
          {
          //load permissions if item has unique permission
          ctx.Load(item, a => a.RoleAssignments.Include(roleAsg => roleAsg.Member.LoginName,
          roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name,
          roleDef => roleDef.Description)));
          ctx.ExecuteQuery();
          foreach (var roleAsg in item.RoleAssignments)
          {
          Console.WriteLine("User/Group: " + roleAsg.Member.LoginName);
          List<string> roles = new List<string>();
          foreach (var role in roleAsg.RoleDefinitionBindings)
          {
          roles.Add(role.Description);
          }
          Console.WriteLine("Permissions: " + string.Join(",", roles.ToArray()));
          Console.WriteLine("----------------");
          }
          }
          else
          {
          Console.WriteLine("No unique permission found");
          }
          Console.WriteLine("###############");
          }
          }



          https://www.morgantechspace.com/2017/09/get-item-level-permissions-sharepoint-csom.html




          Or



          public static void HasUniquePermission()
          {
          OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

          string siteUrl = "https://******.sharepoint.com/sites/DeveloperSite/";
          string userName = "Sathish@********.onmicrosoft.com";
          string password = "********";

          using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
          {
          Web web = ctx.Web;
          ctx.Load(web.Lists);
          ctx.Load(web);

          ctx.ExecuteQueryRetry();

          List list = web.Lists.GetByTitle("D1");
          ctx.Load(list);
          ctx.Load(list, li => li.HasUniqueRoleAssignments);
          ctx.ExecuteQuery();

          System.Console.WriteLine(Convert.ToString(list.HasUniqueRoleAssignments));
          }
          }



          http://www.sharepointpals.com/post/SharePoint-Office-365-How-to-Get-the-Lists-with-Unique-Permissions-Programmatically-C-CSOM







          share|improve this answer













          No directly such API in Graph now. But you can try the permissions API and then try and some filter.



          For CSOM:



          using (var ctx = new ClientContext(sitrUrl))
          {
          //ctx.Credentials = Your Credentials
          ctx.Load(ctx.Web, a => a.Lists);
          ctx.ExecuteQuery();
          List list = ctx.Web.Lists.GetByTitle("Documents");
          var listItems = list.GetItems(CamlQuery.CreateAllItemsQuery());
          //load all list items with default properties and HasUniqueRoleAssignments property
          ctx.Load(listItems, a => a.IncludeWithDefaultProperties(b => b.HasUniqueRoleAssignments));
          ctx.ExecuteQuery();
          foreach (var item in listItems)
          {
          Console.WriteLine("List item: " + item["FileRef"].ToString());
          if (item.HasUniqueRoleAssignments)
          {
          //load permissions if item has unique permission
          ctx.Load(item, a => a.RoleAssignments.Include(roleAsg => roleAsg.Member.LoginName,
          roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name,
          roleDef => roleDef.Description)));
          ctx.ExecuteQuery();
          foreach (var roleAsg in item.RoleAssignments)
          {
          Console.WriteLine("User/Group: " + roleAsg.Member.LoginName);
          List<string> roles = new List<string>();
          foreach (var role in roleAsg.RoleDefinitionBindings)
          {
          roles.Add(role.Description);
          }
          Console.WriteLine("Permissions: " + string.Join(",", roles.ToArray()));
          Console.WriteLine("----------------");
          }
          }
          else
          {
          Console.WriteLine("No unique permission found");
          }
          Console.WriteLine("###############");
          }
          }



          https://www.morgantechspace.com/2017/09/get-item-level-permissions-sharepoint-csom.html




          Or



          public static void HasUniquePermission()
          {
          OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

          string siteUrl = "https://******.sharepoint.com/sites/DeveloperSite/";
          string userName = "Sathish@********.onmicrosoft.com";
          string password = "********";

          using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
          {
          Web web = ctx.Web;
          ctx.Load(web.Lists);
          ctx.Load(web);

          ctx.ExecuteQueryRetry();

          List list = web.Lists.GetByTitle("D1");
          ctx.Load(list);
          ctx.Load(list, li => li.HasUniqueRoleAssignments);
          ctx.ExecuteQuery();

          System.Console.WriteLine(Convert.ToString(list.HasUniqueRoleAssignments));
          }
          }



          http://www.sharepointpals.com/post/SharePoint-Office-365-How-to-Get-the-Lists-with-Unique-Permissions-Programmatically-C-CSOM








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 1:59









          Seiya SuSeiya Su

          1,4221210




          1,4221210













          • Thank you Seiya, this is the solution if there is no direct api to do this.

            – Long
            Nov 30 '18 at 1:55



















          • Thank you Seiya, this is the solution if there is no direct api to do this.

            – Long
            Nov 30 '18 at 1:55

















          Thank you Seiya, this is the solution if there is no direct api to do this.

          – Long
          Nov 30 '18 at 1:55





          Thank you Seiya, this is the solution if there is no direct api to do this.

          – Long
          Nov 30 '18 at 1:55




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53508076%2fis-there-any-efficient-method-to-query-unique-permission-list-items-under-the-li%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks