1

Using CSOM Search API is there a way to filter for only files? Something similar to the following ListItem filter would be ideal:

ListItem.FileSystemObjectType.Equals(FileSystemObjectType.File)

Ex use case:

if (item.FileSystemObjectType.Equals(FileSystemObjectType.File))
{
    // do stuff
}

The only thing similar I have found in documentation would be using the filetype Keyword Query Language (KQL) filter:

filetype:docx

I'd like to avoid using that, however, as setting all the possible valid file types feels like a sloppy solution IMO. Thanks for any feedback!

1

You can use IsDocument managed property to filter out the list items. The search Get API should look like this

http://server/_api/search/query?querytext='QueryText+And+IsDocument:true'

apart from IsDocument managed property you can also use

  1. contentclass:STS_ListItem_DocumentLibrary - if you want to search within document libraries only
  2. contenttype:CONTENT_TYPE_NAME - if you want to search documents for particular content type.
1
  • 1
    Thanks, IsDocument should work perfectly for my use case and a clean solution. Just to note for other users I am using CSOM so would be 'IsDocument:1' in this case.
    – OtoNoOto
    Jul 7 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.