question

MaximilianoBertoli-2614 avatar image
0 Votes"
MaximilianoBertoli-2614 asked saldana-msft edited

Search file for exact match

I have a file called "ABC_file1.docx".

Performing this search I can find my file:

         var fileName = "ABC_file1.docx";

         var files = _graphClient
           .Drives[<My_Drive_ID>]
           .Root
           .ItemWithPath("My_Sub_Folder")
           .Search(fileName)
           .Request()
           .GetAsync()
           .Result;

This also works if I search a file called "ABC_ABC_file1.docx", but this is an issue for me.

How can I search for exact match?

microsoft-graph-sdkmicrosoft-graph-filesmicrosoft-graph-search
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Adding right tags/teams to assist

0 Votes 0 ·

1 Answer

Danstan-MSFT avatar image
0 Votes"
Danstan-MSFT answered MaximilianoBertoli-2614 commented

If you have the full filename and need an exact match why not just do a filter on name? Like GET /me/drive/root/children?$filter=name eq 'ABC_file1.docx'.
The essence of a search is to match the text against the name of the file and return anything that matches to some degree of accuracy and ABC_ABC_file1 query against ABC_file1 will matches the last 10 characters of the query


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Danstan,
thanks for your answer.

filter=name eq 'ABC_file1.docx' is what i missed!

I modifiy my C# query like this:

         var fileName = "ABC_file1.docx";
         var files = _graphClient
             .Drives[<My_Drive_ID>]
             .Root
             .ItemWithPath("My_Sub_Folder")
             .Children
             .Request()
             .Filter($"name eq '{fileName}'")
             .GetAsync()
             .Result;

Thanks!!

Max

1 Vote 1 ·