Cut the Clutter: Test Ignore Files Feature - sign up to become a beta tester here!
Forum Discussion
wwaag76
5 years agoHelpful | Level 6
ListFolderAsync Does Not Return Newly Added Folders
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
- Greg-DB5 years ago
Dropbox Community Moderator
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.
- wwaag765 years agoHelpful | 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-DB5 years ago
Dropbox Community Moderator
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.
- wwaag765 years agoHelpful | 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.
And here's what in DB--15 folders.
I added "Folder 2" to DB, but that folder is never returned. I've changed folder names to no avail.
- Greg-DB5 years ago
Dropbox Community Moderator
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.
- wwaag765 years agoHelpful | 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.
- ddixit3 years agoExplorer | 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;
} - Здравко3 years agoLegendary | 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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,037 PostsLatest Activity: 10 hours ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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!