cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We've been busy working on some major updates to the Community, so check out what's changing, what’s staying the same and what you can expect from the Dropbox Community right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

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

bmilinski
Helpful | Level 6
Go to solution

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).

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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

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! 

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

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

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
Helpful | Level 6
Go to solution

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

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    bmilinski Helpful | Level 6
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?