cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

ListFolderAsync Does Not Return Newly Added Folders

ListFolderAsync Does Not Return Newly Added Folders

wwaag76
Helpful | Level 6

All I want to do is get a list of subfolders within the Root folder.  However, if I or another member adds a new folder, it does not show up.  Here's the code I'm using.

 

async Task ListRootFolder(DropboxClient dbx)
{
var list = await dbx.Files.ListFolderAsync(string.Empty);
folders.Clear();
foreach (var item in list.Entries.Where(i => i.IsFolder))
{
folders.Add(item.Name);
}

8 Replies 8

Greg-DB
Dropbox Staff

Is the ListFolderResult.HasMore returned by ListFolderAsync set to true? If so, you need to call back to ListFolderContinueAsync to retrieve more results. Please refer to the ListFolderAsync documentation for more information.

wwaag76
Helpful | Level 6

Still not working.  Here's my revised code.

 

async Task ListRootFolder(DropboxClient dbx)
{
folders.Clear();
var list = await dbx.Files.ListFolderAsync(string.Empty);
if (list.HasMore)
{
list = await dbx.Files.ListFolderContinueAsync(list.Cursor);
}
foreach (var item in list.Entries.Where(i => i.IsFolder))
{
folders.Add(item.Name);
}
}

 

Greg-DB
Dropbox Staff

You need to check HasMore on each result, including from ListFolderContinueAsync, not just the first one. The number of total pages that will be used is not guaranteed.

 

Also, you should use the contents of each returned page of results. In this latest code it looks like you're only iterating through the contents of the last 'list' returned by ListFolderContinueAsync, but are ignoring the original 'list' returned by ListFolderAsync.

wwaag76
Helpful | Level 6

Just to be clear, I'm only talking about a small number of folders.  Here's what's returned in my little app-14 folders.

folders1.png

And here's what in DB--15 folders.

folders2.png

I added "Folder 2" to DB, but that folder is never returned.  I've changed folder names to no avail.

Greg-DB
Dropbox Staff

The page size returned by ListFolderAsync and ListFolderContinueAsync is not guaranteed. Even if there is currently only a relatively small number of folders, the exact number of calls needed may vary, so you need to make sure you're calling back whenever HasMore is true, and checking the contents of each page. 

 

Beyond that, make sure you're connected to the right account and app and are looking in the right place. For instance, if you're using an app with the "app folder" access type, it will only have access to the contents of the special app folder created for the app, by default at "/Apps/<app folder name>", for accounts with the English locale. Make sure you're not accidentally looking at a different copy of the folder, for instance, when comparing with the web site.

wwaag76
Helpful | Level 6

Just added a little message box indicating whether HasMore is true.  It returns false, so I'll look for the other things you mentioned.  Thanks for your time.

ddixit
Explorer | Level 3

i had the same issue,  i was able to fix it using while : 


public static List<FolderNameModel> ListRootFolder(DropboxClient dbx, string Path)
{
List<PathModel> Paths_ = GetPath();
var folders = new List<FolderNameModel>();
var list = dbx.Files.ListFolderAsync(Path).Result;
while (list.HasMore)
{
list = dbx.Files.ListFolderContinueAsync(list.Cursor).Result;
}

foreach (var item in list.Entries.Where(i => i.IsFolder))
{
folders.Add(new FolderNameModel { FolderName = item.Name });
}
return folders;
}

Здравко
Legendary | Level 20

Hi @ddixit,

Would be really strange if the code you posted:


@ddixit wrote:

...
while (list.HasMore)
{
list = dbx.Files.ListFolderContinueAsync(list.Cursor).Result;
}

foreach (var item in list.Entries.Where(i => i.IsFolder))
{
folders.Add(new FolderNameModel { FolderName = item.Name });
}
...


... works correct and fixes something. You just jump over all pages and list just the last one! The only difference with the 'revised' code above is that instead of only the second (or first) page you're listing only the last one. 🤷 That would work only when all folders fit in a single page. Otherwise you will miss some of the folders (all listed in pages, if any, before the last one). 😉

Good luck.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    ddixit Explorer | Level 3
  • User avatar
    wwaag76 Helpful | Level 6
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?