cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in hearing how one of our Community members uses Dropbox for sailing trips? Read all about it 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: 

why is FolderId / SharedParentFolderId null or just missing for FileMetadata retrievals?

why is FolderId / SharedParentFolderId null or just missing for FileMetadata retrievals?

sbrownnw
Explorer | Level 4
Go to solution

 

      static void Main(string[] args)
      {
         DropboxClientConfig config = new DropboxClientConfig
         {
            MaxRetriesOnError = 0
         };
         DropboxClient dropboxClient = new DropboxClient(AccessToken.ValidToken, config);
         var result = dropboxClient.Files.ListFolderAsync("").Result;
         var folderMetadata = result.Entries.Where(e => e.IsFolder).First() as FolderMetadata;
         result = dropboxClient.Files.ListFolderAsync(folderMetadata?.PathLower).Result;
         var fileMetadata = result.Entries.Where(e => e.IsFile).First() as FileMetadata;
         Debug.WriteLine($"fileMetadata is null: {fileMetadata == null} - folderId from ListFolderAsync: {fileMetadata?.ParentSharedFolderId}");
         fileMetadata = dropboxClient.Files.GetMetadataAsync(fileMetadata?.Id).Result as FileMetadata;
         Debug.WriteLine($"fileMetadata is null: {fileMetadata == null} - folderId from GetMetadataAsync: {fileMetadata?.ParentSharedFolderId}");
      }

 

Running above code returns the following:

 

sbrownnw_0-1686081949594.png

 

 

1 Accepted Solution

Accepted Solutions

DB-Des
Dropbox Engineer
Go to solution

A feature request has been filed to include the parent folder ID in the metadata response object.

 

I cannot promise when and if this will be implemented.

View solution in original post

7 Replies 7

Greg-DB
Dropbox Staff
Go to solution

The parent shared folder ID is only returned if the item is contained inside a shared folder. (Note that new folders in your home folder are not shared by default.) If the item is not in a shared folder, then ParentSharedFolderId will not be set. The output you shared indicates that the file you're checking is not in a shared folder.

 

By the way, note that Metadata.ParentSharedFolderId is deprecated in favor of FileSharingInfo.SharingInfo.ParentSharedFolderId and FolderSharingInfo.SharingInfo.ParentSharedFolderId, so you should use fileMetadata?.SharingInfo?.ParentSharedFolderId instead. Note that SharingInfo will likewise not be set if the file is not in a shared folder.

sbrownnw
Explorer | Level 4
Go to solution

Feature request please for a File / Folder metadata item to always return its parent FolderId (whether it is shared or not).  Both path and parent FolderId are very important metadata items for these types.

Greg-DB
Dropbox Staff
Go to solution

To clarify, FolderMetadata.Id and Metadata.ParentSharedFolderId are different types of identifiers.

 

Shared folder IDs (such as in ParentSharedFolderId) are only created once a folder is shared. They can't always be returned since they may not exist yet.

 

File and folder IDs (such as in FileMetadata.Id and FolderMetadata.Id) however, exist for all non-deleted files and folders. You can get always them from the FileMetadata or FolderMetadata. For example, that would be folderMetadata.Id or fileMetadata.Id in your sample code. If you have only the FileMetadata, you can get the FolderMetadata for its parent by using GetMetadataAsync and passing in the path of the parent (that is, the path of the file without its last path component).

sbrownnw
Explorer | Level 4
Go to solution

I don't think you are understanding what we need.  Given a File or Folder Metadata, I need its parent FolderId, all the time.  Given the current API, it does not return that.

Greg-DB
Dropbox Staff
Go to solution

In your original sample code here, you already have access to the parent folder's ID (not the same as the shared folder ID), in folderMetadata.Id.

 

In cases where you don't already have that parent folder metadata object though, you can retrieve the parent folder ID, given the metadata of a file (or folder), like this:

var parentFolderPath = Directory.GetParent(fileMetadata.PathLower).ToString();
var parentFolderId = dropboxClient.Files.GetMetadataAsync(parentFolderPath).Result.AsFolder.Id;

(Note that this is just a basic example, and assumes that the parent of fileMetadata is not root itself.)

sbrownnw
Explorer | Level 4
Go to solution

yes, I know how to get it.  if we are recursing down a deep folder hierarchy it with ListFolderAsync and building it up in memory, it would sure be nice for all the subfolders and subfolders of subfolders all to have the parent FolderId without having to make additional calls.

DB-Des
Dropbox Engineer
Go to solution

A feature request has been filed to include the parent folder ID in the metadata response object.

 

I cannot promise when and if this will be implemented.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    DB-Des Dropbox Engineer
  • User avatar
    sbrownnw Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?