<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Getting Parent Directory of Current Folder in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Getting-Parent-Directory-of-Current-Folder/m-p/383673#M21357</link>
    <description>&lt;P&gt;I am trying to retrieve the parent folder of the current folder I am in to make it easier to trace permissions amongst folders.&amp;nbsp; I currently am able to list every user's folder, permissions, etc., but is there anyway to use the "item" variable in the code below to directly access its parent folder's name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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 =&amp;gt; a.Profile.Email))
                {
                    int count = 0;
                    //get each user
                    var userClient = DBTeamClient.AsMember(member.Profile.TeamMemberId);
                    //actions to check
                    var actionsToCheck = new FolderAction[] { FolderAction.EditContents.Instance, FolderAction.InviteEditor.Instance };
                    //get each user's file information
                    var list = await userClient.Sharing.ListFoldersAsync(actions: actionsToCheck);  // actions can optionally be supplied to check the permissions the user has for specific actions                   
                                                                                                    //loop through the list of file and show permissions on folders

                    foreach (var item in list.Entries)
                    {
                        int length = item.AccessType.ToString().Length - 32 - 2;
                        System.Diagnostics.Debug.WriteLine("");
                        System.Diagnostics.Debug.WriteLine(member.Profile.Name.DisplayName);                       
                        System.Diagnostics.Debug.WriteLine(item.Name);
                        System.Diagnostics.Debug.WriteLine(item.AccessType.ToString().Substring(32, length));
                        System.Diagnostics.Debug.WriteLine(count + "");
                        count++;
                    }
                    System.Diagnostics.Debug.WriteLine(count + " total folders");
                }
            }&lt;/PRE&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;EDIT: I noticed item contains a "ParentSharedFolderId" member, but how can I use this to find the name of the parent?&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2019 18:20:57 GMT</pubDate>
    <dc:creator>bmilinski</dc:creator>
    <dc:date>2019-12-11T18:20:57Z</dc:date>
    <item>
      <title>Getting Parent Directory of Current Folder</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Getting-Parent-Directory-of-Current-Folder/m-p/383673#M21357</link>
      <description>&lt;P&gt;I am trying to retrieve the parent folder of the current folder I am in to make it easier to trace permissions amongst folders.&amp;nbsp; I currently am able to list every user's folder, permissions, etc., but is there anyway to use the "item" variable in the code below to directly access its parent folder's name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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 =&amp;gt; a.Profile.Email))
                {
                    int count = 0;
                    //get each user
                    var userClient = DBTeamClient.AsMember(member.Profile.TeamMemberId);
                    //actions to check
                    var actionsToCheck = new FolderAction[] { FolderAction.EditContents.Instance, FolderAction.InviteEditor.Instance };
                    //get each user's file information
                    var list = await userClient.Sharing.ListFoldersAsync(actions: actionsToCheck);  // actions can optionally be supplied to check the permissions the user has for specific actions                   
                                                                                                    //loop through the list of file and show permissions on folders

                    foreach (var item in list.Entries)
                    {
                        int length = item.AccessType.ToString().Length - 32 - 2;
                        System.Diagnostics.Debug.WriteLine("");
                        System.Diagnostics.Debug.WriteLine(member.Profile.Name.DisplayName);                       
                        System.Diagnostics.Debug.WriteLine(item.Name);
                        System.Diagnostics.Debug.WriteLine(item.AccessType.ToString().Substring(32, length));
                        System.Diagnostics.Debug.WriteLine(count + "");
                        count++;
                    }
                    System.Diagnostics.Debug.WriteLine(count + " total folders");
                }
            }&lt;/PRE&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;EDIT: I noticed item contains a "ParentSharedFolderId" member, but how can I use this to find the name of the parent?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 18:20:57 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Getting-Parent-Directory-of-Current-Folder/m-p/383673#M21357</guid>
      <dc:creator>bmilinski</dc:creator>
      <dc:date>2019-12-11T18:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Parent Directory of Current Folder</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Getting-Parent-Directory-of-Current-Folder/m-p/383687#M21360</link>
      <description>&lt;P&gt;Yes, there are a few options here, depending on exactly what you're looking for. I've illustrated and commented on them in code:&lt;/P&gt;
&lt;PRE&gt;// get the name of the parent shared folder, if any
// note that the parent shared folder is not necessarily the immediate parent folder of the item
if (item.ParentSharedFolderId != null) {
    Console.WriteLine("item ParentSharedFolderId: " + item.ParentSharedFolderId);
    var parentSharedFolderMetadata = await userClient.Sharing.GetFolderMetadataAsync(item.ParentSharedFolderId);
    Console.WriteLine("item ParentSharedFolder Name: " + parentSharedFolderMetadata.Name);
}

// get the parent folder name by taking the next to last path component
if (item.PathLower != null) {
    var pathComponents = item.PathLower.Split('/');
    Console.WriteLine("item parent component: " + pathComponents.ElementAtOrDefault(pathComponents.Count() - 2));
    // more ideally, you would pass the path string into some path library to do the parsing for you.
}

// get the parent folder name from the metadata
// this was recently added to the API, but isn't available in the .NET SDK yet. it should be included with the next release of the SDK
//if (item.ParentSharedFolderId != null)
//{
//    Console.WriteLine(item.ParentFolderName);
//}&lt;/PRE&gt;
&lt;P&gt;Hope this helps!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 19:10:43 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Getting-Parent-Directory-of-Current-Folder/m-p/383687#M21360</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-12-11T19:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Parent Directory of Current Folder</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Getting-Parent-Directory-of-Current-Folder/m-p/383690#M21361</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/10"&gt;@Greg-DB&lt;/a&gt;&amp;nbsp;Thank you for the quick reply and useful information. I ran the code, but got the following error:&lt;/P&gt;&lt;P&gt;"Exception User-Unhandled: Dropbox.Api.ApiException`1: 'not_a_member/..'&lt;/P&gt;&lt;P&gt;on this line of your code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var parentSharedFolderMetadata = await userClient.Sharing.GetFolderMetadataAsync(item.ParentSharedFolderId);&lt;/PRE&gt;&lt;P&gt;Is there anyway to avoid this exception from occurring? Or does this have to do with how the folders are setup in my company's Dropbox?&lt;/P&gt;&lt;P&gt;EDIT: The error is being caused by some folders who don't have parent directories, so I added a try/catch statement to catch this exception. It seems to catch all other parent folders and works correctly, thanks for the help.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 21:06:28 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Getting-Parent-Directory-of-Current-Folder/m-p/383690#M21361</guid>
      <dc:creator>bmilinski</dc:creator>
      <dc:date>2019-12-11T21:06:28Z</dc:date>
    </item>
  </channel>
</rss>

