We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
bmilinski
5 years agoHelpful | Level 6
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...
- 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!
Greg-DB
5 years agoDropbox Staff
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!
- bmilinski5 years agoHelpful | Level 6
Greg-DB Thank you for the quick reply and useful information. I ran the code, but got the following error:
"Exception User-Unhandled: Dropbox.Api.ApiException`1: 'not_a_member/..'
on this line of your code:
var parentSharedFolderMetadata = await userClient.Sharing.GetFolderMetadataAsync(item.ParentSharedFolderId);
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?
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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 2 hours agoIf 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!