You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

cristpol95's avatar
cristpol95
Explorer | Level 4
9 months ago

How to perform a query search with Dropbox API 2?

Hey guys, I am creating a "login" system, which is not really a login system, but an environment for the students to access their files in their own respective folder and avoid manipulation of the same files from other students.

 

I am trying to create a "failsafe" where is the student is not found within the dropbox environment, then the program takes the first letter of the first name of the student and the first name of the last name of the student, then it proceeds to search all the students that have those initials in their first name and last name. 

 

Once it finds those folders, then it shows all of the students and then the student is able to select which account is theirs; otherwise we manually create a folder for the student.

 

This is the code that performs the query search: 

 

private async Task<List<string>> SearchStudentNames(DropboxClient dropbox, string firstName, string lastName)
{
var similarNames = new List<string>();

try
{
// Construct the query
var query = $"{firstName.ToLower().First()}*.{lastName.ToLower().First()}*";

// Perform the search
var searchResult = await dropbox.Files.SearchV2Async(query);

Debug.WriteLine(searchResult.Matches.Count);

// Extract folder names from the search result
foreach (var match in searchResult.Matches)
{
Debug.WriteLine("1" + match);

// Check if the matched item represents a folder
if (match.Metadata.AsMetadata.Value.IsFolder)
{
// Extract the folder name and add it to the list
similarNames.Add(match.Metadata.AsMetadata.Value.Name);
}
}
}
catch (Exception ex)
{
// Handle exception, e.g., Dropbox API error
// Log the exception or return an empty list in case of failure
Debug.WriteLine("2" + ex.Message);
}

return similarNames;
}

 

However, this code does not work, it returns 0. I just started using SearchAsyncV2, so I need help with understanding what I am missing here.

 

Thanks everyone for your help.

 

 

  • cristpol95 Здравко is correct; the Dropbox API search functionality does not support regex or wildcard functionality, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    Hi cristpol95,

    It's easy, just don't assume the method you're using works with regular expressions (unfortunately). 🤷 Where did you read this? 🧐 In general it's good idea not to assume anything if not explicitly written somewhere. 😉 In your situation you're looking for file or folder named exactly as your query string or the query string is part either of the file/folder name or file content. Is there such thing? That's why you got empty list (not 0 by the way). There is no way to turn search to regular expression mode - it's unsupported. Let's hope such support will be added at some point.

    Hope this clarifies matter.

    • cristpol95's avatar
      cristpol95
      Explorer | Level 4
      But are you not able to perform a folder search just how you can find a file in Windows lets say, where I specify a path and what I want to search?
    • cristpol95's avatar
      cristpol95
      Explorer | Level 4

      I just thought you would be able to use wildcards to search for anything past a certain letter by using the asterisk. 

       

      I appreciate your response. Thank you!

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    cristpol95 Здравко is correct; the Dropbox API search functionality does not support regex or wildcard functionality, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,882 PostsLatest Activity: 3 years 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!