0

I have a file called "ABC_file1.docx". I want to perform a search of a specific file name in a specific folder.

My code is:

            var fileName = "ABC_file1.docx";

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

Unfortunately this works not only for my file, but also for a similar file name, like "ABC_ABC_file1.docx", and that's not what i need.

How can I search for exact match?

Max Bertoli
  • 614
  • 5
  • 25

2 Answers2

0

Have you tried leveraging documentation here for searchable site properties and see if this helps.

Thanks!

Shweta
  • 351
  • 1
  • 4
0

I just found a solution and seems that the "Search" method is not what it needs for exact match file search.

It's better to use "Filter" rather than "Search" 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;

This resolve not only the problem of the searching about exact match, but also the issue which renaming a name on Sharepoint the update is being visible after 10/15 minutes (known issue).

Max Bertoli
  • 614
  • 5
  • 25