Search Files with Graph SDK

APIPointNewbie 146 Reputation points
2021-08-13T18:50:35.887+00:00

Hello, I would like to search for a file with the Graph SDK(ASP.Net Core and C#), with Postman this also works as desired.

https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/search(q='Filename')

But I just can't get it to work with the SDK (empty collection).

private async Task<IDriveItemSearchCollectionPage> SearchFiles(GraphServiceClient graphClient){
  var search = await graphClient.Users["User-iD"].Drive.Root
    .Search("Filename")
    .Request()
    .GetAsync();

    return search;
}

And the associated iterator:

 private void PrintFiles(IDriveItemSearchCollectionPage files) {

        foreach(var file in files) {
          var message = $"File: {file.Name}, Id: {file.Id}";

          Console.WriteLine(message);
        }
    }

What am I doing wrong ?

I would be very happy to receive help.

Greetings

Microsoft Security | Microsoft Graph
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

Developer technologies | ASP.NET Core | Other

1 answer

Sort by: Newest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    2 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.