We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

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

Getting Parent Directory of Current Folder

I am trying to retrieve the parent folder of the current folder I am in to make it easier to trace permissions amongst folders.  I currently am able to list every user's folder, permissions, etc., bu...
  • Greg-DB's avatar
    5 years ago

    Yes, there are a few options here, depending on exactly what you're looking for. I've illustrated and commented on them in code:

    // 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);
    //}

    Hope this helps! 

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 2 hours ago
325 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!