You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

bmilinski's avatar
bmilinski
Helpful | Level 6
6 years ago

How to get each team member's permissions per folder using .NET Dropbox API?

I am trying to go through all the members of my Dropbox and find out their permissions on every folder, but I'm not sure how to do this. I am new to the API, so help would be appreciated. I am writing in C# as seen in my code:

 public MainPage()
        {
            this.InitializeComponent();
            var task = Task.Run((Func<Task>)MainPage.Run);
            task.Wait();
        }

        //Async task to
        static async Task Run()
        {
            
            //use dropbox client with access token from app console
            using (DropboxTeamClient DBTeamClient = new DropboxTeamClient("MYACCESSKEY"))
            {
                //get all the dropbox members
                var members = await DBTeamClient.Team.MembersListAsync();
                //loop through all members ordered by email alphabetical             
                foreach (var member in members.Members.OrderBy(a => a.Profile.Email))
                {
                    //get each user
                    var userClient = DBTeamClient.AsMember(member.Profile.TeamMemberId);
                    //get each user's file information
                    var list = await userClient.Files.ListFolderAsync(string.Empty);                   
                    //loop through the list of file and show permissions on folders
                    foreach (var item in list.Entries.OrderBy(b => b.PathDisplay))
                    {
                        //only display folder information
                        if (item.IsFolder)
                        {
                           //get folder permissions here??
                        }
                    }
                }
            }
        }

I'd appreciate more of an explanation or example rather than a link to API documentation (as they contain no implementation examples so are not much help).

  • [Cross-linking for reference: https://stackoverflow.com/questions/59272078/dropbox-api-how-to-see-each-team-members-folder-permissions#59272078 ]

    When you list files and folders using FilesUserRoutes.ListFolderAsync like this, you're listing the contents of the member's Dropbox folder, which will include both shared folders (where they have some specific permission level) as well as their private folders (where they don't have a specific permission level, since it's just their folders). For shared folders, the returned FolderMetadata.SharingInfo will be set, but it doesn't contain information about that user's permission level in that folder. (By the way, make sure you implement ListFolderContinueAsync as well, to make sure you can retrieve all results, when using ListFolderAsync. Check out the ListFolderAsync documentation for more information.)

    Instead, if you want to list the shared folders the user has access to, including their level of access in each one, you should use SharingUserRoutes.ListFoldersAsync. Likewise, make sure you implement SharingUserRoutes.ListFoldersContinueAsync too, as this interface is also paginated. Each returned SharedFolderMetadata will list the user's AccessType and Permissions.

    Here's a little example:

    var actionsToCheck = new Dropbox.Api.Sharing.FolderAction[] { Dropbox.Api.Sharing.FolderAction.EditContents.Instance, Dropbox.Api.Sharing.FolderAction.InviteEditor.Instance };
    var list = await userClient.Sharing.ListFoldersAsync(actions: actionsToCheck);  // actions can optionally be supplied to check the permissions the user has for specific actions
    
    foreach (var item in list.Entries)
    {
        Console.WriteLine(item.SharedFolderId);
        Console.WriteLine(item.PathLower);  // only set if the folder is mounted
        Console.WriteLine(item.AccessType);
        Console.WriteLine(item.Permissions);
    }
    
    // and so on, iterating over pages from userClient.Sharing.ListFoldersContinueAsync if list.Cursor is set

    Hope this helps! 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    [Cross-linking for reference: https://stackoverflow.com/questions/59272078/dropbox-api-how-to-see-each-team-members-folder-permissions#59272078 ]

    When you list files and folders using FilesUserRoutes.ListFolderAsync like this, you're listing the contents of the member's Dropbox folder, which will include both shared folders (where they have some specific permission level) as well as their private folders (where they don't have a specific permission level, since it's just their folders). For shared folders, the returned FolderMetadata.SharingInfo will be set, but it doesn't contain information about that user's permission level in that folder. (By the way, make sure you implement ListFolderContinueAsync as well, to make sure you can retrieve all results, when using ListFolderAsync. Check out the ListFolderAsync documentation for more information.)

    Instead, if you want to list the shared folders the user has access to, including their level of access in each one, you should use SharingUserRoutes.ListFoldersAsync. Likewise, make sure you implement SharingUserRoutes.ListFoldersContinueAsync too, as this interface is also paginated. Each returned SharedFolderMetadata will list the user's AccessType and Permissions.

    Here's a little example:

    var actionsToCheck = new Dropbox.Api.Sharing.FolderAction[] { Dropbox.Api.Sharing.FolderAction.EditContents.Instance, Dropbox.Api.Sharing.FolderAction.InviteEditor.Instance };
    var list = await userClient.Sharing.ListFoldersAsync(actions: actionsToCheck);  // actions can optionally be supplied to check the permissions the user has for specific actions
    
    foreach (var item in list.Entries)
    {
        Console.WriteLine(item.SharedFolderId);
        Console.WriteLine(item.PathLower);  // only set if the folder is mounted
        Console.WriteLine(item.AccessType);
        Console.WriteLine(item.Permissions);
    }
    
    // and so on, iterating over pages from userClient.Sharing.ListFoldersContinueAsync if list.Cursor is set

    Hope this helps! 

    • bmilinski's avatar
      bmilinski
      Helpful | Level 6

      I appreciate the detailed response and time taken to answer the question. Thank you for the help!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,915 PostsLatest Activity: 5 hours ago
333 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!