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.