cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

How to perform a query search with Dropbox API 2?

How to perform a query search with Dropbox API 2?

cristpol95
Explorer | Level 4
Go to solution

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.

 

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

@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.

View solution in original post

5 Replies 5

Здравко
Legendary | Level 20
Go to solution

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
Explorer | Level 4
Go to solution
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?

Greg-DB
Dropbox Staff
Go to solution

@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.

cristpol95
Explorer | Level 4
Go to solution

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!

cristpol95
Explorer | Level 4
Go to solution

Thank you for clarifying, the situation!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    cristpol95 Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?